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

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.



Got any PHP Question?