PHP has different types of operators for different operations. They are as follows:
Arithmetic operators are used to perform arithmetic operations.
| Name | Operator | Example |
|---|---|---|
| Addition | + | $x + $y |
| Subtraction | - | $x - $y |
| Multiplication | * | $x * $y |
| Division | / | $x / $y |
| Modulus | % | $x % $y |
| Exponentiation | ** | $x ** $y |
These operators are used to assign values to variables.
| Name | Evaluated as |
|---|---|
| = | a = b |
| += | a = a + b |
| -= | a = a - b |
| *= | a = a * b |
| /= | a = a / b |
| %= | a = a % b |
These operators are used to compare two values.
| Name | Operator | Example |
|---|---|---|
| Equal | == | $x == $y |
| Identical | === | $x === $y |
| Not equal | != | $x != $y |
| Not equal | <> | $x <> $y |
| Not Identical | !== | $x !== $y |
| Greater than | > | $x > $y |
| Less than | < | $x < $y |
| Greater than or equal to | >= | $x >= $y |
| Less than or equal to | <= | $x <= $y |
| Spaceship | <=> | $x <=> $y |
These operators are used to increment/decrement a variable's value.
| Name | Operator |
|---|---|
| Pre-Increment | ++$x |
| Post-Increment | $x++ |
| Pre-decrement | --$x |
| Post-decrement | $x-- |
These are the logical operators that combine conditional statements.
| Name | Operator | Example |
|---|---|---|
| And | and | $x and $y |
| Or | or | $x or $y |
| Xor | xor | $x xor $y |
| And | && | $x && $y |
| Or | || | $x || $y |
| Not | ! | !$x |
PHP has these two operators designed for strings.
| Name | Operator | Example |
|---|---|---|
| Concatenation | . | $text1 . $text2 |
| Concatenation Assignment | .= | $text1 .= $text2 |
These operators are used to compare arrays.
| Name | Operator | Example |
|---|---|---|
| Union | + | $x + $y |
| Equality | == | $x == $y |
| Identity | === | $x === $y |
| Inequality | != | $x != $y |
| Inequality | <> | $x <> $y |
| Non-Identity | !== | $x !== $y |
These operators assign values to operands based on the outcome of a certain condition.
| Name | Operator | Example |
|---|---|---|
| Ternary | ?: | $x = exp1 ? exp2 : exp3 |
| Null Coalescing | ?? | $x = exp1 ?? exp2 |