First line:
($x = true) and false; //$x will be true
The result of true
is obviously true
, so true
is assigned to $x
. The second expression after and
is also executed, because true
is true
, but the result of false
(which is false) is never assigned to something.
$y = (true and false); //$y will be false
In this case, there are parenthesis around the expression says, that the result of whole expression should be assigned to $y
. As true
is true
, the second expression is also evaluted (like in the first one). But the result of the whole expression is false
, because the second expression is false
.
Example from the docs:
// The constant true is assigned to $h before the "and" operation occurs
// Acts like: (($h = true) and false)
$h = true and false;