How to concatenate multiple ternary operator in PHP? [duplicate]

Those parenthesis are what I think is getting you.

Try

$foo = 1;
$bar = ($foo == 1) ? "1" : (($foo == 2)  ? "2" : "other");
echo $bar;

Leave a Comment