Created
August 26, 2012 16:03
-
-
Save mauris/3481335 to your computer and use it in GitHub Desktop.
Bitwise &= for multiple boolean checks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function op($d){ | |
return $d; | |
} | |
$ok = true; | |
$ok &= op(true); | |
$ok &= op(true); | |
$ok &= op(true); | |
var_dump((bool)$ok); // yields true because all op()s are true. | |
// another scenario | |
$ok = true; | |
$ok &= op(true); | |
$ok &= op(false); | |
$ok &= op(true); | |
var_dump((bool)$ok); // yields false because one of the op()s is false. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment