Php Tutorial logical operators
Example name result
$ A and $ B And (logical and) TRUE, if both $ a And $ B are TRUE.
$ A or $ B Or (logical or) TRUE, if $ a Or $ B is TRUE.
$ A xor $ B Xor (logical exclusive or) TRUE. If either $ a or $ B is TRUE, but not both.
! $ A Not (logical Not) TRUE, if $ a is Not TRUE.
$ A & $ B And (logical And) TRUE, if both $ a And $ B are TRUE.
$ A | $ B Or (logical Or) TRUE. If $ a Or $ B is set to TRUE.
<? Php
$ A = true;
$ B = false;
Echo "And (logical And)"; // TRUE, if both $ a And $ B are TRUE
Echo $ a and $ B; // return null false;
Echo "Or (logical Or)"; // TRUE, if both $ a and $ B are TRUE
Echo $ a or $ B; // returns 1 TRUE;
Echo "Xor (logical OR)"; // TRUE, if either $ a or $ B is TRUE, but not both
Echo $ a xor $ B; // returns 1 TRUE;
Echo "Not (logical Not)"; // TRUE, if $ a is Not TRUE
Echo! $ A; // return null false;
Echo "And (logical And)"; // TRUE, if both $ a And $ B are TRUE
Echo $ a & $ B; // return null false;
Echo "Or (logical Or)"; // TRUE, if $ a Or $ B is TRUE
Echo $ a | $ B; // returns 1 TRUE;
?>
<? Php
// The following foo () will not be called because they are short-circuited by the operator.
$ A = (false & foo ());
$ B = (true | foo ());
$ C = (false and foo ());
$ D = (true or foo ());
// "|" Has a higher priority than "or"
$ E = false | true; // $ e is assigned (false | true) and returns true.
$ F = false or true; // $ f is assigned to false. [Altair note: "=" has a higher priority than "or"]
Var_dump ($ e, $ f );
// "&" Has a higher priority than "and"
$ G = true & false; // $ g is assigned to (true & false) and the result is false.
$ H = true and false; // $ h is assigned true [Altair note: "=" priority is higher than "and"]
Var_dump ($ g, $ h );
?>
The output of the preceding routine is similar:
Bool (true)
Bool (false)
Bool (false)
Bool (true)