Bit Mask Tricks (PHP & MySQL)

Very useful for testing switches:

MySQL test:

SELECT * FROM menus WHERE (Roles & BIT) = BIT

MySQL set:

UPDATE table SET field = (field | 8 )

MySQL reset:

UPDATE table SET field = ((field | 8 )  ^8)

PHP:

if (($VALIDATION & 8) == 8

PHP (SET):

function setflag (&$var, $flag, $set = true)
{
  
$var = $set ? ($var | $flag) : ($var & ~$flag);
}