Skip to content

Instantly share code, notes, and snippets.

@mauris
Created August 26, 2012 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mauris/3481335 to your computer and use it in GitHub Desktop.
Save mauris/3481335 to your computer and use it in GitHub Desktop.
Bitwise &= for multiple boolean checks
<?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