The precedence of an operator specifies how "tightly" it binds two expressions together.
For example, in the expression 1 + 2 * 3
the multiplication ("*") operator has a higher precedence than the addition ("+") operator.
When operators have equal precedence their associativity decides how the operators are grouped.
1+2+3
Parentheses may be used to force precedence. (1 + 2) * 3
| Associativity | Operators | Additional Information |
|---|---|---|
| Associativity | Operators | Additional Information |
| non-associative | clone new | clone and new |
| left | [ | array() |
| right | ** | arithmetic |
| right | ++ -- ~ (int) (float) (string) (array) (object) (bool) @ | types and increment/decrement |
| non-associative | instanceof | types |
| right | ! | logical |
| left | * / % | arithmetic |
| left | + - . | arithmetic and string |
| left | << >> | bitwise |
| non-associative | < <= > >= | comparison |
| non-associative | == != === !== <> <=> | comparison |
| left | & | bitwise and references |
| left | ^ | bitwise |
| left | | | bitwise |
| left | && | logical |
| left | || | logical |
| right | ?? | null coalescing |
| left | ? : | ternary |
| right | = += -= *= **= /= .= %= &= |= ^= <<= >>= | assignment |
| right | yield from | yield from |
| right | yield | yield |
| left | and | logical |
| left | xor | logical |
| left | or | logical |