I use ternary operators alot but I can't seem to stack multiple ternary operator inside each other.
I am aware that stacking multiple ternary operator would make the code less readable but in some case I would like to do it.
This is what I've tried so far :
$foo = 1;
$bar = ( $foo == 1 ) ? "1" : ( $foo == 2 ) ? "2" : "other";
echo $bar; // display 2 instead of 1
What is the correct syntax ?