Last active
December 11, 2015 23:28
-
-
Save ziadoz/4676706 to your computer and use it in GitHub Desktop.
PHP Ternary (Left/Right Associative)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
// Left associative ternary. | |
// Output: T | |
echo (true ? 'True' : false ? 'T' : 'F') . "\n"; | |
// This is essentially the same as above. | |
// Output: T | |
echo ((true ? 'True' : false) ? 'T' : 'F') . "\n"; | |
// Right associative ternary. | |
// Output: True | |
echo (true ? 'True' : (false ? 'T' : 'F')) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment