- $a && $b : TRUE if both $a and $b are TRUE.
- $a || $b : TRUE if either $a or $b is TRUE.
- $a xor $b : TRUE if either $a or $b is TRUE, but not both.
- ! $a : TRUE if $a is not TRUE.
- $a and $b : TRUE if both $a and $b are TRUE.
- $a or $b : TRUE if either $a or $b is TRUE.
- $a == $b : TRUE if $a is equal to $b after type juggling.
- $a === $b : TRUE if $a is equal to $b, and they are of the same type.
- $a != $b : TRUE if $a is not equal to $b after type juggling.
- $a <> $b : TRUE if $a is not equal to $b after type juggling.
- $a !== $b : TRUE if $a is not equal to $b, or they are not of the same type.
- $a < $b : TRUE if $a is strictly less than $b.
- $a > $b : TRUE if $a is strictly greater than $b.
- $a <= $b : TRUE if $a is less than or equal to $b.
- $a >= $b : TRUE if $a is greater than or equal to $b.
- $a <=> $b : An integer less than, equal to, or greater than zero when $a is respectively less than, equal to, or greater than $b. Available as of PHP 7.
- $a ? $b : $c : if $a return $b else return $c (ternary operator)
- $a ?? $c : Same as $a ? $a : $c (null coalescing operator - requires PHP>=7)
- -$a : Opposite of $a.
- $a + $b : Sum of $a and $b.
- $a - $b : Difference of $a and $b.
- $a * $b : Product of $a and $b.
- $a / $b : Quotient of $a and $b.
- $a % $b : Remainder of $a divided by $b.
- $a ** $b : Result of raising $a to the $b'th power (introduced in PHP 5.6)
- ++$a : Increments $a by one, then returns $a.
- $a++ : Returns $a, then increments $a by one.
- --$a : Decrements $a by one, then returns $a.
- $a-- : Returns $a, then decrements $a by one.
- $a & $b : Bits that are set in both $a and $b are set.
- $a | $b : Bits that are set in either $a or $b are set.
- $a ^ $b : Bits that are set in $a or $b but not both are set.
- ~ $a : Bits that are set in $a are not set, and vice versa.
- $a << $b : Shift the bits of $a $b steps to the left (each step means "multiply by two")
- $a >> $b : Shift the bits of $a $b steps to the right (each step means "divide by two")
- $a . $b : Concatenation of $a and $b.
- $a + $b : Union of $a and $b.
- $a == $b : TRUE if $a and $b have the same key/value pairs.
- $a === $b : TRUE if $a and $b have the same key/value pairs in the same order and of the same types.
- $a != $b : TRUE if $a is not equal to $b.
- $a <> $b : TRUE if $a is not equal to $b.
- $a !== $b : TRUE if $a is not identical to $b.
- $a = $b : The value of $b is assigned to $a
- $a += $b : Same as $a = $a + $b
- $a -= $b : Same as $a = $a - $b
- *$a = $b : Same as $a = $a * $b
- $a /= $b : Same as $a = $a / $b
- $a %= $b : Same as $a = $a % $b
- **$a = $b : Same as $a = $a ** $b
- $a .= $b : Same as $a = $a . $b
- $a &= $b : Same as $a = $a & $b
- $a |= $b : Same as $a = $a | $b
- $a ^= $b : Same as $a = $a ^ $b
- $a <<= $b : Same as $a = $a << $b
- $a >>= $b : Same as $a = $a >> $b
- $a ??= $b : The value of $b is assigned to $a if $a is null or not defined (null coalescing assignment operator - requires PHP>=7.4)
Note
and
operator and or
operator have lower precedence than assignment operator =
.
This means that $a = true and false;
is equivalent to ($a = true) and false
.
In most cases you will probably want to use &&
and ||
, which behave in a way known from languages like C, Java or JavaScript.