== compares after type juggling; === also demands the same type. Since PHP 8.0 a number meeting a non-numeric string is compared as a string, so 0 == "foo" is false (true in PHP 7), while two numeric strings still compare as numbers (Type Juggling). && and || short-circuit. The words and and or bind below assignment, which is how $a ends up true, so keep them out of new code. The bitwise operators &, |, ^, ~, << and >> pack flags into one integer, as E_ALL & ~E_DEPRECATED does.
<?php
$a = true and false; // parsed as ($a = true) and false
echo json_encode([0 == "foo", "1e3" == "1000", "1" === 1, 0.1 + 0.2 == 0.3,
abs(0.1 + 0.2 - 0.3) < PHP_FLOAT_EPSILON, $a, true xor true]), "\n";
const READ = 0b001, WRITE = 0b010, DELETE = 0b100;
$perms = READ | WRITE | DELETE; // set three flags
$perms &= ~WRITE; // clear one
printf("%03b can write: %s\n", $perms, ($perms & WRITE) ? 'yes' : 'no');Output
[false,true,false,false,true,true,false] 101 can write: no
The fourth result is why you never test floats with ==: compare the difference with a tolerance, as the fifth does. Use === unless you want juggling.