PHP Operators
Operators and Operands
Up to this point we have been working with only a handful of operators such as the assignment operator and some basic arithmetic operators. PHP offers many other kinds of operators, we’ll cover and explain them in this tutorial.
An operator is a symbol that is used to perform a particular action on a operand, which is the input data used in the operation. For example, in the following expression: 2 + 3, the (+) symbol represents an operator and the numerical values 2 and 3 represent operands. PHP supports three types of operators, unary, binary, and ternary which operate on single operands, two operands, and three operands, respectively.
To hit the ground running, below is a table containing a complete listing of all operators available in PHP, with the highest-precedence operators at the top along with their associativity.
| Operators | Associativity |
|---|---|
| () | N/A |
| new | N/A |
| [] | Right |
| ! ~ ++ — (int) (double) (string) (array) (object) @ | Right |
| / * % | Left |
| + – . | Left |
| < < >> | left |
| < <= > >= | N/A |
| == != === !== | N/A |
| & | Left |
| ^ | Left |
| | | Left |
| && | Left |
| || | Left |
| ? : | Left |
| = += -= *= /= .= %= &= |= ^= ~= < <= >>= | Left |
| Right | |
| AND | Left |
| XOR | Left |
| OR | Left |
| , | Left |
