Operators are used to manipulate or perform operations on variables and values. There are many operators used in PHP, we
have separated them into the following categories.
# Assignment Operators
# Arithmetic Operators
# Comparison Operators
# Logical Operators
Assignment operators are used to set a variable equal to a value or set a variable to another variable's value. ‘=’ is
used for assignment operator.
Example:
$var = 23;
$var2 = $var;
| Operator | Example | Is The Same As |
| = | a=b | a=b |
| += | a+=b | a=a+b |
| -= | a-=b | a=a-b |
| *= | a*=b | a=a*b |
| /= | a/=b | a=a/b |
| .= | a.=b | a=a.b |
| %= | a%=b | a=a%b |
Arithmetic Operators:
| Operator | Function |
| + | Addition |
| - | Subtraction |
| * | Multiplication |
| / | Division |
| % | Modulus (division remainder) |
| ++ | Increment |
| -- | Decrement |
| Operator | Function | Example | Result |
| == | Equal To | $x == $y | false |
| != | Not Equal To | $x != $y | true |
| < | Less Than | $x < $y | true |
| > | Greater Than | $x > $y | false |
| <= | Less Than or Equal To | $x <= $y | true |
| >= | Greater Than or Equal To | $x >= $y | false |
Logical Operators:
| Operator | Function | Example |
| && | and | x=8 y=4 (x <> 1) returns true |
| || | or | x=12 y=8 (x>=5 || y<=5) returns true |
| ! | not | x=6 y=3 !(x==y) returns true |