Press "Enter" to skip to content


PHP Logical Operators

PHP Logical Operator are and or not

$a and $bAndTRUE if both $a and $b are TRUE.
$a or $bOrTRUE if either $a or $b is TRUE.
$a xor $bXorTRUE if either $a or $b is TRUE, but not both.
! $aNotTRUE if $a is not TRUE.
$a && $bAndTRUE if both $a and $b are TRUE.
$a || $bOrTRUE if either $a or $b is TRUE.

Example for PHP Logical Operators

$a = true;
$b = false;

if($a && $b) {
echo ‘Both $a and $b are true. <br />’;
// Print the statement if $foo OR $bar is true
if($a || $b) {
echo ‘At least one of the variables is true. <br />’;
// Print the statement if $foo OR $bar is true, but not both
if($a xor $b) {
echo ‘One variable is true, and one is false. <br />’;
// Print the statement if $bar is NOT true
if(!$b) {
echo ‘$b is false. <br />’;