两个变量if为空else other


Two variables if empty else other

对不起,我是一个PHP新手,需要帮助。我有两个变量

<?php echo $LOGO ?>
<?php echo $TITLE ?>

所以我需要使,如果LOGO是空的脚本必须显示标题,但如果一个标志设置比它必须只显示徽标。

多谢!

<?php echo (empty($LOGO) ? $TITLE : $LOGO) ?>
如果$LOGO为空,

将显示$TITLE。否则将只显示$LOGO。

该操作符称为三元操作符。

empty是这样工作的:

The following things are considered to be empty:
- "" (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- $var; (a variable declared, but without a value)