Example:
!defined (' MAGIC_QUOTES_GPC ') && define (' MAGIC_QUOTES_GPC ', GET_MAGIC_QUOTES_GPC ());
O (︶^︶) o Alas, very dizzy, today asked n many people. I finally got the "&&" thing figured out what's going on.
Operators do not have to judge what it means to write, hey, if the front is false. The following statement is not executed. Lest we still bother to write if
How simple it is ...
A simple description, if the previous judgment is False then does not execute, if it is true, continue to perform the following definition of the constant operation.
logical Operators
Example |
name |
Results |
$a and $b |
and (Logic and) |
trueif both the $a and the $b are true. |
$a or $b |
or (logical OR) |
trueif either $a or $b is true. |
$a XOR $b |
Xor (logical XOR OR) |
trueif either $a or $b is true, but not at the same time. |
! $a |
Not (logical non) |
trueIf the $a is not true. |
$a && $b |
and (Logic and) |
trueif both the $a and the $b are true. |
$a | | $b |
or (logical OR) |
trueif either $a or $b is true. |
Example #1 Logical Operators Example
Copy Code code as follows:
<?php
The following foo () is not invoked because they are "shorted out" 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 the result is true
$f = False or true; The $f is assigned false [Altair NOTE: "=" has a higher precedence than "or"]
Var_dump ($e, $f);
"&&" has higher precedence than "and"
$g = True && false; The $g is assigned (true && false) and the result is false
$h = True and false; The $h is assigned a value of true [Altair Note: "=" has a higher precedence than "and"]
Var_dump ($g, $h);
?>
The output of the example above is similar to the following:
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 this 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" for you should never mix &&s and | | S with ANDs and ORs without paretheses.
For example:
<?php
True && false | | False
?>
returns false, but
<?php
True and False | | False
?>
Returns True.