Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
是否可以回显 using ||,以便它使用第一个评估为 true 的变量?
||
例如,
$a = false; $b = 'b'; echo $a || $b || 'neither'; // evaluates to 1 ?
三元运算符
echo (($a) ? : $b) ? : 'neither';
echo $a ? $a : ($b ? $b : ($c ? $c : 'neither'));
如果有更多的变量,你会这样继续下去,但如果太长,它会变得丑陋且难以阅读。
终极三元
$a = false; $b = 'b'; echo ($a)?$a:(($b)?$b:'neither');