Specifications
FIGURE 1.5
The totals of the customer’s order have been calculated, formatted, and displayed.
The total amount seems to be correct, but why were the multiplications performed before the
additions? The answer lies in the precedence of the operators, that is, the order in which they
are evaluated.
Precedence and Associativity: Evaluating
Expressions
In general, operators have a set precedence, or order, in which they are evaluated.
Operators also have an associativity, which is the order in which operators of the same prece-
dence will be evaluated. This is generally left-to-right (called left for short), right-to-left (called
right for short), or not relevant.
Table 1.6 shows operator precedence and associativity in PHP.
In this table, the lowest precedence operators are at the top, and precedence increases as you
go down the table.
TABLE 1.6 Operator Precedence in PHP
Associativity Operators
left ,
left or
Using PHP
P
ART I
34
03 7842 CH01 3/6/01 3:39 PM Page 34