Using return in ternary operator

前端 未结 7 889
無奈伤痛
無奈伤痛 2020-12-03 17:46

I\'m trying to use return in a ternary operator, but receive an error:

Parse error: syntax error, unexpected T_RETURN 

Here\'s the code:

7条回答
  •  一生所求
    2020-12-03 17:56

    No. But you can have a ternary expression for the return statement.

    return (!$e) ? '' : array('false', $e);
    

    Note: This may not be the desired logic. I'm providing it as an example.

提交回复
热议问题