The difference between && and AND in PHP
You may have heard something about operator priority before, for example that 1+2*3
results in 7
and not 9
(You always calculate first *
and /
and after that +
and -
).
So in PHP the order of AND and OR statements is:
- &&
-
- AND
- XOR
- OR
Example:
<?php
// That's the same as $a||($b&&$C)
$a || $b && $C;
// That's the same as ($a||$b)&&$C
$a || $b AND $C;
?>
AND
, XOR
and OR
are the lowest operators in PHP. So, all other operators are executed first.
Written on November 20, 2022