PHP 三元运算符?:的小坑

$a = ['result'=123];
$b = !empty($a['result'])?:-1;
$c = !empty($a['result'])?$a['result']:-1;
var_dump($b,$c);

  上述代码输出结果为  true 和 123 。

如果?和:中间项省略  如果条件表达式为真则返回ture   否则返回:后的结果。

posted @ 2019-06-13 16:02  初心未泯  阅读(658)  评论(0编辑  收藏  举报