Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
<?php
$ok = true && false;
$ok2 = true and false;
var_dump($ok, $ok2);bool(false) bool(true)
- Expecting
andto work like&&: both compute the same value, butandbinds weaker than=, so$ok2 = true and falsestorestrueand drops the result. - Expecting
=to run before&&:&&binds tighter than=, so$ok = true && falsestores the result of the whole expression,false.
- How would you change the second line so that
$ok2getsfalse? - What does
$x = false or true;leave in$x, and why?