Php如果为空变量

时间:2015-10-16 01:09:33

标签: php

所以,我有以下变量:

<?php
$multi_images = image($image, $rh_post_id);
?>

然后,我想只在变量不为空时显示这样的东西。 我不知道最好的办法是什么。

<?php if ( empty($multi_images())) { ?>                         
    no images
<?php }else{ ?>
    there is an image
<?php } ?>  

这是对的吗?

谢谢!

2 个答案:

答案 0 :(得分:2)

我这样编码,假设$ multi_images是一个图像数组。

<?php if ( isset($multi_images) && is_array($multi_images) && count($multi_images) > 0) : ?>                         
    no images
<?php else : ?>
    there is an image
<?php endif ?> 

答案 1 :(得分:1)

您是在调用变量还是函数?

multi_images();

if (empty(image($image, $rh_post_id))){  ... }

每一个都不同。如果要验证来自您将使用的函数的响应:

if (empty($image)){ ... }

关于变量:

!

检查响应是否为空。您需要使用感叹号if (!empty($var)){ .. } ,因此它将是:

List<? extends T> generics;

将转换为

  

如果变量不为空

相关问题