Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Last active December 11, 2015 23:28
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/4676706 to your computer and use it in GitHub Desktop.
Save ziadoz/4676706 to your computer and use it in GitHub Desktop.
PHP Ternary (Left/Right Associative)
#!/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