The precedence of PHP operators (high to low)
| Operator(s) | Type |
|---|---|
| () | Parentheses |
| ++ -- | Increment/decrement |
| ! | Logical |
| * / % | Arithmetic |
| + - . | Arithmetic and string |
| << >> | Bitwise |
| < <= > >= <> | Comparison |
| == != === !== | Comparison |
| & | Bitwise (and references) |
| ^ | Bitwise |
| | | Bitwise |
| && | Logical |
| || | Logical |
| ? : | Ternary |
| = += -= *= /= .= %= &= != ^= <<= >>= | Assignment |
| and | Logical |
| xor | Logical |
| or | Logical |
Operator associativity
| Operator | Description | Associativity |
|---|---|---|
| CLONE NEW | Create a new object | None |
| < <= >= == != === !== <> | Comparison | None |
| ! | Logical NOT | Right |
| ~ | Bitwise NOT | Right |
| ++ -- | Increment and decrement | Right |
| (int) | Cast to an integer | Right |
| (double) (float) (real) | Cast to a floating-point number | Right |
| (string) | Cast to a string | Right |
| (array) | Cast to an array | Right |
| (object) | Cast to an object | Right |
| @ | Inhibit error reporting | Right |
| = += -= *= /= | Assignment | Right |
| .= %= &= |= ^= <<= >>= | Assignment | Right |
| + | Addition and unary plus | Left |
| - | Subtraction and negation | Left |
| * | Multiplication | Left |
| / | Division | Left |
| % | Modulus | Left |
| . | String concatenation | Left |
| << >> & ^ | | Bitwise | Left |
| ?: | Ternary | Left |
| || && and or xor | Logical | Left |
| , | Separator | Left |