PHP assignment with a default value

前端 未结 5 2105
春和景丽
春和景丽 2021-02-20 01:48

What\'s a nicer way to do the following, that doesn\'t call f() twice?

$x = f() ? f() : \'default\';
5条回答
  •  礼貌的吻别
    2021-02-20 02:05

    function f()
    {
      // conditions 
      return $if_something ? $if_something : 'default';
    }
    
    $x = f();
    

提交回复
热议问题