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 の 2 つの変数があります。var1 のデフォルトを表示したいのですが、var1 が空または null の場合は var2 を表示します。var2 値があるかどうかに関係なく。
echo empty($var1)? $var2 : $var1;
関数付きの三項演算子?:を使用して実行できますIsset()。
?:
Isset()
<?php echo (isset($var1) && !empty($var1) ? $var1 : $var2); ?>
それはトリックを行う必要があります:)