- iPhone (2)
- Learning (42)
- Linux (4)
- Debian (1)
- Mac Terminal / Linux (5)
- Other Stuff (1)
- Programming (66)
- Slim Framework (1)
- WordPress (5)
$x = true and false; var_dump($x);
This one is interesting. In PHP, you can use
and to do a logical comparison.
However, due to the Operator Precedence rules,
and actually has lower precedence than
&& 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