Logical operators are used when we want to combine operations and
expressions into a set of logical comparisons. They are usually used in
conjuction with "if and "else" statements to lay out the dynamic logic
we need in many situations as we advance in our PHP development.
example:-
Name | Usage | Result |
And | $var1 && $var2 | TRUE if both $var1 and $var2 are TRUE |
And | $var1 and $var2 | TRUE if both $var1 and $var2 are TRUE |
Or | $var1 or $var2 | TRUE if either $var1 or $var2 is TRUE |
Or | $var1 || $var2 | TRUE if either $var1 or $var2 is TRUE |
Xor | $var1 xor $var2 | TRUE if either $var1 or $var2 is TRUE, but not both |
Is Not | !$var1 | TRUE if $var1 is not TRUE |
example:-