PHP Logical Operators (&&/AND and ||/OR)


Example

In PHP, there are two versions of logical AND and OR operators.

OperatorTrue if
$a and $bBoth $a and $b are true
$a && $bBoth $a and $b are true
$a or $bEither $a or $b is true
$a || $bEither $a or $b is true

Note that the && and || opererators have higher precedence than and and or. See table below:

EvaluationResult of $eEvaluated as
$e = false || trueTrue$e = (false || true)
$e = false or trueFalse($e = false) or true

Because of this it's safer to use && and || instead of and and or.