最佳答案
PHP 中有没有类似于 JavaScript 的东西:
alert(test || 'Hello');
因此,当 test 未定义或为 null 时,我们将看到 Hello,否则-我们将看到 test 的值。
I tried similar syntax in PHP but it doesn't seem to be working right... Also I've got no idea how to google this problem..
谢谢
剪辑
我应该补充一点,我想在数组中使用它:
$arr = array($one || 'one?', $two || 'two?'); //This is wrong
但事实上,我也可以使用 inline’? :’if 语句,谢谢。
$arr = array(is_null($one) ? "one?" : $one, is_null($two) ? "two ?" : $two); //OK