== | Returns true if the left operand is equal to the right operand. |
!= | Returns true if the left operand is not equal to the right operand. |
=== | Returns true if the left operand is identical to the right operand. This is not the same as == . |
!== | Returns true if the left operand is not identical to the right operand. This is not the same as != . |
< | Returns true if the left operand is smaller than the right operand. |
> | Returns true if the left operand is greater than the right operand. |
<= | Returns true if the left operand is equal to or smaller than the right operand. |
&& | Returns true if both the left operand and the right operand are true. |
|| | Returns true if either the left operand or the right operand is true. |
++ | Increments the operand by one. |
-- | Decrements the operand by one. |
+= | Increments the left operand by the right operand. |
-= | Decrements the left operand by the right operand. |
. | Concatenates the left operand and the right operand (joins them). |
% | Divides the left operand by the right operand and returns the remainder. |
| | Performs a bitwise OR operation. It returns a number with bits that are set in either the left operand or the right operand. |
& | Performs a bitwise AND operation. It returns a number with bits that are set both in the left operand and the right operand. |
There are at least 10 other operators not listed, but to be fair, you're unlikely to use them. Even some of the ones in this list are used infrequently — bitwise AND
, for example. Having said that, the bitwise OR operator is used regularly because it allows you to combine values.
Here is a code example demonstrating some of the operators:
<?php
$i = 100;
$i++; // $i is now 101
$i--; // $i is now 100 again
$i += 10; // $i is 110
$i = $i / 2; // $i is 55
$j = $i; // both $j and $i are 55
$i = $j % 11; // $i is 0
?>
The last line uses modulus, which for some people takes a little bit of effort to under stand. The result of $i % 11
is 0
because $i
is set to 55
and modulus works by dividing the left operand (55
) by the right operand (11
) and returning the remainder. 55 divides by 11 exactly five times, and so has the remainder 0.
The concatenation operator, a period, sounds scarier than it is: It just joins strings together. For