Logical operators are used to combine conditional statements.
and
($x and $y)
True if both $x and $y are true
$x = 40;
$y = 50;
if ($x > 30 and $y > 45) {
echo "True";
}
or
($x or $y)
True if either $x or $y is true
$x = 40;
$y = 50;
if ($x > 30 or $y == 85) {
echo "True";
}
xor
($x xor $y)
True if either $x or $y is true, but not both
$x = 40;
$y = 50;
if ($x > 30 xor $y == 85) {
echo "True";
}
&&
($x && $y)
True if both $x and $y are true
$x = 40;
$y = 50;
if ($x > 30 and $y > 45) {
echo "True";
}
||
($x || $y)
True if either $x or $y is true
$x = 40;
$y = 50;
if ($x > 30 or $y == 85) {
echo "True";
}
!
(!$x)
True if $x is not true
$x = 40;
if ($x !== 50) {
echo "True";
}