Developer Forums | About Us | Site Map
Search  
HOME > PHPMANUAL


Sponsors





Web Host
site hosted by netplex
Partners

Online Manuals

Chapter 10. Operators

Operator Precedence

The precedence of an operator specifies how "tightly" it binds two expressions together. For example, in the expression 1 + 5 * 3, the answer is 16 and not 18 because the multiplication ("*") operator has a higher precedence than the addition ("+") operator. Parentheses may be used to force precedence, if necessary. For instance: (1 + 5) * 3 evaluates to 18.

The following table lists the precedence of operators with the lowest-precedence operators listed first.

Table 10-1. Operator Precedence

AssociativityOperators
left,
leftor
leftxor
leftand
rightprint
right = += -= *= /= .= %= &= |= ^= <<= >>=
left? :
left||
left&&
left|
left^
left&
non-associative== != === !==
non-associative< <= > >=
left<< >>
left+ - .
left* / %
right! ~ ++ -- (int) (float) (string) (array) (object) @
right[
non-associativenew

Note: Although ! has a higher precedence than =, PHP will still allow expressions similar to the following: if (!$a = foo()), in which case the output from foo() is put into $a.

Copyright 2004-2024 GrindingGears.com. All rights reserved. Site hosted by NETPLEX