$x = true and false;
var_dump($x);
This one is interesting. In PHP, you can use &&
or and
to do a logical comparison.
However, due to the Operator Precedence rules, and
actually has lower precedence than =
, where &&
has higher!
That means that the value of $x will be true.
Two ways to fix this:
$x = (true and false); // evaluates to false
$x = true && false; // evaluates to false
and, it’s not what you expected