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.
我有两个变量:var1 和 var2。我想显示 var1 默认值,但如果 var1 为空或 null,则显示 var2。无论它是否具有 var2 值。
echo empty($var1)? $var2 : $var1;
可以使用带函数的三元运算符来完成。?:Isset()
?:
Isset()
<?php echo (isset($var1) && !empty($var1) ? $var1 : $var2); ?>
这应该够了吧 :)