PHP Logical Operators
Logical operators operate on conditional statements(these are based on conditions) or expressions. Logical operators supported by PHP are And, Or, Xor,&&,||,!.
Operator | Name | Example | Description |
---|---|---|---|
and | Logical AND | $m and $n | Returns true if both of the variables $m and $n are true else it returns false. |
or | Logical OR | $m or $n | Returns true if either of the variables $m and $n are true else it returns false. |
xor | Logical XOR | $m xor $n | Returns true if either of the variables $m and $n are true and else it returns false. |
&& | Logical AND | $m && $n | Returns true if both the variables $m and $n are true else it returns false. |
|| | Logical OR | $m || $n | Returns true if either of the variables $m and $n are true else it returns false. |
! | Logical NOT | !$m | Returns true if $m is false |
PHP - And Operator
True if both a and b are true.
Output:
PHP - Or Operator
True if either a or b is true.
Output:
PHP - Xor Operator
True if either a or b is true but not both true.
Output:
PHP - && Operator
True if both a and b are true and non zero.
Output:
PHP - || Operator
True if either a or b is true and non zero.
Output:
PHP - ! Operator
True if a is not true.
Output: