PHP Tutorials - Herong's Tutorial Examples - Version 4.18, by Dr. Herong Yang
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