3 ms·
Thank god he didn't try php. echo 2 && 1; // 1 echo 1 && 2; // 1 echo 2 || 1; // 1 echo 1 || 2; // 1 echo 2 ?: 1; // 2 In php ?: is javasc
by jcampbell1 13y ago
Thank god he didn't try php.
echo 2 && 1; // 1
echo 1 && 2; // 1
echo 2 || 1; // 1
echo 1 || 2; // 1
echo 2 ?: 1; // 2
In php ?: is javascript's || Unfortunately there is no && that works correctly.
- mattparlane 13y agoCame here to say this. If you use var_dump you can see it's coercing the result to a bool. $ php -r 'var_dump(1 && 2);' bool(true)
- RossM 13y agoExactly, it's not that bizarre. PHP assumes when you're using && you're going to have a boolean outcome. The odd bit is that casting a boolean to a string[0] with echo coerces the result to (string) "1" for true and (string) "" for false. [0]: http://www.php.net/manual/en/language.types.string.php#language.types.string.casting http://www.php.net/manual/en/language.types.string.php#langu...
- comex 13y agoIncidentally, this is identical to the result in GNU C.