如果带有条件的语句已设置并且比较不能一起使用 [英] If statement with condition isset and comparing not working together

查看:62
本文介绍了如果带有条件的语句已设置并且比较不能一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在制作if语句时遇到问题:

I'm having a problems with making if statements:

<?php if (isset($detail) == 1) { ?>
    // code if detail variable exists and is equal to 1
<?php } else { ?>
    // code if detail variable doesn't exist or is not equal 1
<?php }?>

由于某种原因,该条件不起作用.我该如何解决if条件,这样才能正常工作?

For some reason this condition doesn't work. How could I fix the if condition, so it will work?

推荐答案

isset是一个布尔运算符,它返回TRUEFALSE.您无需将其与1进行比较.

isset is a boolean operator which returns TRUE or FALSE. You don't need to compare it to 1.

if( isset($detail) )

作为一个旁注,仅因为设置了变量,并不意味着它不为空.您可能只想检查一下它是否为空:

As a side note, just because the variable is set, does not mean it's not empty. You may want to just check that it's not empty:

if( !empty($detail) )

这篇关于如果带有条件的语句已设置并且比较不能一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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