Recently in the project with a nested ternary operation, take it for granted that no problem, no test on the line (the problem is not good), the results were humiliated by colleagues.
Conditions? True: false, test condition first, if True then execute? After the statement, if False, executes: after the statement.
True?1:-1, the result of the expression is the result of a 1,false?1:-1 expression of-1.
This is not difficult to understand, and I was wrong in nesting when I do not know its binding, is left to combine rather than take for granted right combination.
1 = = $a? 1:2== $a? 2:3
I want to say that if $ A is 1 it returns 1, 2 returns 2, and the other returns 3. The result of the expression above will never be 1;
The above expression is with (1 = = $a? 1:2== $a)? 2:3 equivalent.
And what I really need is 1 = = $a? 1: (2== $a? 2:3)
It is a good habit, by the way, to add parentheses.
PHP ternary operator