What Is an Expression?

This section provides an introduction of what is an expression. A data literal or a variable is a simple expression. A single operation or a group of multiple operations is a complex express.

What Is an Expression? Giving a precise single definition of an expression is not an easy task. So I will try to define it in a recursive way:

1. A simple expression is a presentation of a data value like, a literal, a variable, an element of an array, or a function call.

2. A complex expression is a presentation of a data value returned from an operation represented by an operator, and one or two expressions as operands. The operation will result a new data value.

If you apply rule #2 recursively, an expression may contain multiple operations in a sequence. When this happens, operations must be carried out in an order defined by the following rules:

A. The operation enclosed in a pair of parentheses must be carried out before an operation outside the parentheses.

B. The operation with a higher precedence must be carried out before an operation with lower precedence.

C. The operation on the left must be carried out before the operation on the right.

D. Rule A must be applied before Rule B, which must be applied before Rule C.

Examples of expressions:

   "Hello world!"   # Simple expression - a String literal
   777              # Simple expression - an Integer literal
   $author          # Simple expression - a variable
   getdate()        # Simple expression - a function call

   7*9.99              # Complex expression - an arithmetic operation
   "Hello ".$author    # Complex expression - a string concatenation
   (7+2)*9.99 > 50     # Complex expression - multiple operations

Last update: 2015.

Table of Contents

 About This Book

 Introduction and Installation of PHP 7.0

 PHP Script File Syntax

 PHP Data Types and Data Literals

 Variables, References, and Constants

Expressions, Operations and Type Conversions

What Is an Expression?

 What Is an Operation?

 Precedence of Operations

 Data Type Automatic Conversion

 Conditional Statements - "if" and "switch"

 Loop Statements - "while", "for", and "do ... while"

 Function Declaration, Arguments, and Return Values

 Arrays - Ordered Maps

 Configuring and Sending out Emails

 Retrieving Information from HTTP Requests

 Creating and Managing Sessions in PHP Scripts

 Sending and Receiving Cookies in PHP Scripts

 Controlling HTTP Response Header Lines in PHP Scripts

 MySQL Server Connection and Access Functions

 Functions to Manage Directories, Files and Images

 SOAP Extension Function and Calling Web Services

 SOAP Server Functions and Examples

 Localization Overview of Web Applications

 Using Non-ASCII Characters in HTML Documents

 Using Non-ASCII Characters as PHP Script String Literals

 Receiving Non-ASCII Characters from Input Forms

 "mbstring" Extension and Non-ASCII Encoding Management

 Managing Non-ASCII Character Strings with MySQL Servers

 Introduction of Class and Object

 Integrating PHP with Apache Web Server

 Outdated Tutorials


 PDF Printing Version