Is there a short-circuit OR in PHP that returns the left-most value?

前端 未结 6 2059
南笙
南笙 2020-12-09 16:57

In some languages, you can do

$a = $b OR $c OR die(\"no value\");

That is, the OR will short-circuit, only evaluating values from left to right

6条回答
  •  一向
    一向 (楼主)
    2020-12-09 17:15

    This should work:

    $a = (($f1=func1()) ? $f1 : ($f2=func2()) ?  $f2 : func3()) );
    

提交回复
热议问题