Logical Operators
| Example |
Name |
Result |
$a and $b |
And |
TRUE if both $a
and $b are TRUE. |
$a or $b |
Or |
TRUE if either $a
or $b is TRUE. |
$a xor $b |
Xor |
TRUE if either $a
or $b is TRUE,
but not both. |
! $a |
Not |
TRUE if $a
is not TRUE. |
$a && $b |
And |
TRUE if both $a
and $b are TRUE. |
$a || $b |
Or |
TRUE if either $a
or $b is TRUE. |
Increment/decrement Operators
| Example |
Name |
Effect |
++$a |
Pre-increment |
Increments $a
by one, then returns $a. |
$a++ |
Post-increment |
Returns $a,
then increments $a by one. |
--$a |
Pre-decrement |
Decrements $a
by one, then returns $a. |
$a-- |
Post-decrement |
Returns $a,
then decrements $a by one. |
Arithmetic Operators
| Example |
Name |
Result |
-$a |
Negation |
Opposite of $a. |
$a + $b |
Addition |
Sum of $a and
$b. |
$a - $b |
Subtraction |
Difference of $a and
$b. |
$a * $b |
Multiplication |
Product of $a and
$b. |
$a / $b |
Division |
Quotient of $a and
$b. |
$a % $b |
Modulus |
Remainder of $a
divided by $b. |
Bitwise Operators
| Example |
Name |
Result |
$a & $b |
And |
Bits that are set in both $a
and $b are set. |
$a | $b |
Or (inclusive or) |
Bits that are set in either $a
or $b are set. |
$a ^ $b |
Xor (exclusive or) |
Bits that are set in $a
or $b but not both are set. |
~ $a |
Not |
Bits that are set in $a
are not set, and vice versa. |
$a << $b |
Shift left |
Shift the bits of $a
$b steps to the left (each step means "multiply
by two") |
$a >> $b |
Shift right |
Shift the bits of $a
$b steps to the right (each step means "divide
by two") |
Comparison Operators
Comparison operators, as their name implies, allow you to compare two values.
| Example |
Name |
Result |
$a == $b |
Equal |
TRUE if $a
is equal to $b after type
juggling. |
$a === $b |
Identical |
TRUE if $a
is equal to $b, and they
are of the same type. (introduced in PHP 4) |
$a != $b |
Not equal |
TRUE if $a
is not equal to $b after
type juggling. |
$a <> $b |
Not equal |
TRUE if $a
is not equal to $b after
type juggling. |
$a !== $b |
Not identical |
TRUE if $a
is not equal to $b, or
they are not of the same type. (introduced in PHP 4) |
$a < $b |
Less than |
TRUE if $a
is strictly less than $b. |
$a > $b |
Greater than |
TRUE if $a
is strictly greater than $b. |
$a <= $b |
Less than or equal to |
TRUE if $a
is less than or equal to $b. |
$a >= $b |
Greater than or equal to |
TRUE if $a
is greater than or equal to $b. |