Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created April 16, 2013 21:13
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ziadoz/5399694 to your computer and use it in GitHub Desktop.
Save ziadoz/5399694 to your computer and use it in GitHub Desktop.
PHP Operator Precedence '&&' vs 'AND', '||' vs 'OR'
<?php
// See: http://stackoverflow.com/questions/2803321/and-vs-as-operator
// http://www.php.net/manual/en/language.operators.precedence.php
$foo = true;
$bar = false;
$truthiness = $foo && $bar;
echo ($truthiness ? 'TRUE' : 'FALSE'); // FALSE
$truthiness = $foo and $bar;
echo ($truthiness ? 'TRUE' : 'FALSE'); // TRUE
$truthiness = $bar || $foo;
echo ($truthiness ? 'TRUE' : 'FALSE'); // TRUE
$truthiness = $bar or $foo;
echo ($truthiness ? 'TRUE' : 'FALSE'); // FALSE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment