Operatori booleani in PHP
Un semplice esempio che mostra la differenza tra && – and e || – or
<?php /** * AND */ echo '&&' . "\n"; $bool = true && false; echo 'true && false: ' . (int)$bool . "\n";// false $bool = false && true; echo 'false && true: ' . (int)$bool . "\n"; // false echo 'AND' . "\n"; $bool = true and false; echo 'true and false: ' . (int)$bool . "\n"; // true $bool = false and true; echo 'false and true: ' . (int)$bool . "\n"; // false /** * OR */ echo '||' . "\n"; $bool = true || false; echo 'true || false: ' . (int)$bool . "\n"; // true $bool = false || true; echo 'false || true: ' . (int)$bool . "\n"; // true echo 'OR' . "\n"; $bool = true or false; echo 'true or false: ' . (int)$bool . "\n"; // true $bool = false or true; echo 'false or true: ' . (int)$bool . "\n"; // false
Di seguito l’output:
&& true && false: 0 false && true: 0 AND true and false: 1 false and true: 0 || true || false: 1 false || true: 1 OR true or false: 1 false or true: 0
Reference: qui