unusual ternary operation
问题 I was asked to perform this operation of ternary operator use: $test='one'; echo $test == 'one' ? 'one' : $test == 'two' ? 'two' : 'three'; Which prints two (checked using php). I am still not sure about the logic for this. Please, can anybody tell me the logic for this. 回答1: Well, the ? and : have equal precedence, so PHP will parse left to right evaluating each bit in turn: echo ($test == 'one' ? 'one' : $test == 'two') ? 'two' : 'three'; First $test == 'one' returns true, so the first