PHP operator priority
PHP operator priority describes the order in which operations are performed when a computer evaluates an expression. Operations with higher priority are performed first, and then operations with lower priority are performed. For example, we often say that multiplication and division are performed first, and then addition and subtraction operations are performed.
Priority | Binding direction | Operator | Additional information |
---|---|---|---|
1 | Non-binding | clone new | clone and new |
2 | Left | [ | array() |
3 | Non-binding | ++ -- | Increment/decrement operator |
4 | Non-associative | ~-(int)(float)(string)(array)(object)(bool)@ | Type |
5 | Non-associative | instanceof | Type |
6 | Right-associative | ! | Logical Operator |
7 | Left | */ % | Arithmetic Operator |
8 | Left | + -. | Arithmetic and String Operators |
9 | Left | <<>> | Bitwise Operators |
10 | Non-Associative | <<=>>=<> | Comparison Operators |
11 | Non-Associative | ==!====!== | Comparison Operators |
12 | Left | & | Bitwise Operators and References |
13 | Left | ^ | Bitwise Operators |
14 | Left | | | Bitwise Operators |
15 | Left | && | Logical Operators |
16 | Left | || | Logical Operators |
17 | Left | ?: | Ternary Operator |
18 | Right | =+=-=*=/= .= %= &= |= ^= <<= >>= | Assignment Operator |
19 | Left | and | Logical Operators |
20 | Left | xor | Logical Operator |
21 | Left | or | Logical Operator |
22 | Left | , | Used in many places |