unusual ternary operation

后端 未结 7 735
别那么骄傲
别那么骄傲 2020-12-18 21:56

I was asked to perform this operation of ternary operator use:

$test=\'one\';

echo $test == \'one\' ? \'one\' :  $test == \'two\' ? \'two\' : \'three\';
         


        
7条回答
  •  星月不相逢
    2020-12-18 22:29

    Ternary operators are executed in order of appearance so you really have:

    echo ($test == 'one' ? 'one' :  $test == 'two') ? 'two' : 'three';
    

提交回复
热议问题