两个变量如果为空则为其他 [英] Two variables if empty else other

查看:109
本文介绍了两个变量如果为空则为其他的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

抱歉,我是PHP的菜鸟,需要帮助。我有两个变量

Sorry i am a noob in PHP and need help. I have two variables

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

所以我需要这样做,如果LOGO为空,脚本必须显示标题,但如果徽标是设置比它必须只显示徽标。

So i need to make that if LOGO is empty the script must show title, but if a logo is set than it must show only the logo.

非常感谢!

推荐答案

<?php echo (empty($LOGO) ? $TITLE : $LOGO) ?>

如果$ LOGO为空,

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

will show $TITLE if $LOGO is empty. Otherwise will only show $LOGO.

此运算符称为三元运算符

的工作原理如下:

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)

这篇关于两个变量如果为空则为其他的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆