Example:
!defined (' MAGIC_QUOTES_GPC ') && define (' MAGIC_QUOTES_GPC ', GET_MAGIC_QUOTES_GPC ());
O (︶^︶) o Alas, very faint, today asked n many people. Finally get the "&&" thing figured out what's going on.
Operators are not judged to write what it means, eh, if the previous is false. The subsequent statement will not be executed. Lest we bother to write if
So much simpler ...
Simply stated, if the previous judgment is False then do not execute, if it is true, proceed to the following definition of the constant operation.
logical Operators
Example |
name |
Results |
$a and $b |
and (Logical AND) |
trueif $a and $b are true. |
$a or $b |
or (logical OR) |
trueif either $a or $b is true. |
$a XOR $b |
Xor (Logical XOR) |
trueif either $a or $b is true, but not at the same time. |
! $a |
Not (logical) |
trueIf the $a is not true. |
$a && $b |
and (Logical AND) |
trueif $a and $b are true. |
$a | | $b |
or (logical OR) |
trueif either $a or $b is true. |
Example #1 Logical Operator Example
Copy CodeThe code is as follows:
<?php
The following foo () is not called because they are "shorted" 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 a value of (false | | true), and the result is true
$f = False or true; $f is assigned false [Altair NOTE: ' = ' has a higher precedence than ' or ']
Var_dump ($e, $f);
"&&" has a higher priority than "and"
$g = True && false; $g is assigned (true && false) and the result is false
$h = True and false; $h is assigned true [Altair Note: ' = ' has a higher precedence than ' and ']
Var_dump ($g, $h);
?>
The output of the previous example 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 and the types of ands have a different order of precedence. "&&" is higher than "and", and the "?:" operator just happens to come between the other. Also, since "| |" (or) is actually higher than "and," 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.
PHP && Logic and operator usage instructions