Example:
! Defined ('Magic _ QUOTES_GPC ') & define ('Magic _ QUOTES_GPC', get_magic_quotes_gpc ());
O (zookeeper) o alas, I was dizzy. Today I asked N more people. Finally, I figured out what was going on "&".
The operator does not determine what it means. Well, if the previous operator is false. The subsequent statements are not executed. So that we do not have to write if
This is simple...
// Simple Description: if the previous judgment is false, the operation is not executed. If the judgment is true, the following definition constant operation is continued.
Logical operators
Example |
Name |
Result |
$ A and $ B |
And (logical And) |
TRUEIf both $ a and $ B areTRUE. |
$ A or $ B |
Or (logical Or) |
TRUEIf either $ a or $ B isTRUE. |
$ A xor $ B |
Xor (logical exclusive or) |
TRUEIf either $ a or $ B isTRUEBut not at the same time. |
! $ |
Not (logical non) |
TRUEIf $ a is notTRUE. |
$ A & $ B |
And (logical And) |
TRUEIf both $ a and $ B areTRUE. |
$ A | $ B |
Or (logical Or) |
TRUEIf either $ a or $ B isTRUE. |
Example #1 Example of logical operators
Copy codeThe Code is as follows:
<? 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 in the above example is similar:
Bool (true)
Bool (false)
Bool (false)
Bool (true)
Another example that might help.
<? Php
(Isset ($ panelemail )&&! Empty ($ panelemail )? $ Panelemail: $ userdata ['email ']);
?>
Returns the userdata email address, but this
<? Php
(Isset ($ panelemail) AND! Empty ($ panelemail )? $ Panelemail: $ userdata ['email ']);
?>
Returns false.
The reason is that the two types of ands have a different order of precedence. "&" is higher than "AND", and "? : "Operator just happens to come between the two. also, since "|" (or) is actually higher than "AND," you shoshould never mix & s and | s with ANDs and ORs without paretheses.
For example:
<? Php
True & false | false
?>
Returns false,
<? Php
True AND false | false
?>
Returns true.