The entire expression on the left is evaluated. These are the same:
echo( ('a' == 'a') ? 'A' : ('a' == 'b') ? 'B' : 'C');
echo((('a' == 'a') ? 'A' : ('a' == 'b')) ? 'B' : 'C');
The expression below evaluates to A
:
('a' == 'a') ? 'A' : ('a'=='b');
And this express evaluates to B
:
('A' ? 'B' : 'C');
If you move the parentheses, the expression will evaluate as you're expecting:
echo(('a' == 'a') ? 'A' : (('a' == 'b') ? 'B' : 'C'));