Operator Syntax Result ========================================================================== AND $op1 and $op2 TRUE if both $op1 and $op2 are TRUE. OR $op1 or $op2 TRUE if either $op1 or $op2 is TRUE. XOR $op1 xor $op2 TRUE if either $op1 or $op2 is TRUE, but not both. NOT !$op TRUE if $op is not TRUE. AND $op1 && $op2 TRUE if both $op1 and $op2 are TRUE. OR $op1 || $op2 TRUE if either $op1 or $op2 is TRUE.Example 1: Logical AND Operator
<?php $a = 10; $b = 20; var_dump($a>5 AND $b>5); var_dump($a && $b); ?>
Output
bool(true) bool(true)
<?php $a = 10; $b = 20; var_dump($a>30 OR $b>30); var_dump($a || $b); ?>
Output
bool(false) bool(false)
<?php $a = 10; var_dump(!($a>5)); ?>
Output
bool(false)
<?php $a = 10; $b = 20; $c = 40; $d = 50; var_dump($a>5 XOR $b>5); var_dump($c>5 XOR $c>70); ?>
Output
bool(false) bool(true)
PHP boolean operators always return a boolean value. || has a greater precedence than OR && has a greater precedence than AND |