When I evaluate the expressions below, the result is completely different depending on the evaluation order and whether I assign the value or not:
$a = true;
$b = false;
var_dump($a and $b); // false
$c = $a and $b;
var_dump($c); // true
$d = $b and $a;
var_dump($d); // false
I’m completely stumped. Why does this happen?
=has higher priority thanand. So$c = $a and $b;is the same as($c = $a) and $b;, value of $a is assigned to $c. This is different from&&which has higher priority than=, so$c = $a && $bevaluates to$c = ($a && $b);