O'Reilly logo

Core PHP Programming, Third Edition by Leon Atkinson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.6. Building Expressions

When computing the value of an expression made out of several operators, PHP evaluates operators according to their precedence value, as shown in Table 2.13. Operators with lower precedence values evaluate first. Consider the evaluation of 2 + 2 * 2. Since the multiplication operator * has precedence over the addition operator +, evaluation begins with the computation of 2 * 2. PHP then adds 2 to 4 and returns the result of 6.

Precedence alone, however, is not enough. Consider the expression 12 / 2 * 3. Both operators appearing in this expression, division and multiplication, have the same precedence. However, the result of this expression will vary depending on which operation we perform first. That is, (12 / 2) * 3 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required