unusual ternary operation

后端 未结 7 723
别那么骄傲
别那么骄傲 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:40

    Nested ternary operations are gross! The above explanation shows why.

    Basically this is the logic:

    is $test == 'one'
    
      if TRUE then echo 'one'
    
      else is $test == 'two'
    
          if TRUE then echo 'two'
    
          else echo three
    
    0 讨论(0)
提交回复
热议问题