Specifications
left xor
left and
right print
left = += -= *= /= .= %= &= |= ^= ~= <<= >>=
left ? :
left ||
left &&
left |
left ^
left &
n/a == != ===
n/a < <= > >=
left << >>
left + - .
left * / %
right ! ~ ++ -- (int) (double) (string) (array) (object) @
right []
n/a new
n/a ()
Notice that the highest precedence operator is one we haven’t covered yet: plain old parenthe-
ses. The effect of these is to raise the precedence of whatever is contained within them. This is
how we can work around the precedence rules when we need to.
Remember this part of the last example:
$totalamount = $totalamount * (1 + $taxrate);
If we had written
$totalamount = $totalamount * 1 + $taxrate;
the multiplication operator, having higher precedence than the addition operator, would be per-
formed first, giving us an incorrect result. By using the parentheses, we can force the sub-
expression 1 + $taxrate to be evaluated first.
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
35
TABLE 1.6 Continued
Associativity Operators
03 7842 CH01 3/6/01 3:39 PM Page 35