In the PHP manual, I find the following 'user contributed note' under "Operators".
Note that in php the ternary operator ?: has a left associativity unlike in C and C++ where it has right associativity.
You cannot write code like this (as you may have accustomed to in C/C++):
$a = 2;
$a == 1 ? 'one' :
$a == 2 ? 'two' :
$a == 3 ? 'three' :
$a == 4 ? 'four' : 'other');
// prints 'four'
Because your whole expression evaluates as if it was
(......) ? 'four' : 'other'. Since the first element is probably something truthy, it gives you
'four'. In saner languages, where
?: has right associativity, the whole expression evaluates as if it was
$a == 1 ? 'one' : (......), where if
$a is not
1, you go on to test other things.