PHP检查False还是Null [英] PHP check if False or Null

查看:99
本文介绍了PHP检查False还是Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当从函数返回时,如何检查变量是否为false/null也让我感到困惑.

I also get confused how to check if a variable is false/null when returned from a function.

何时使用empty()和何时使用isset()检查条件?

When to use empty() and when to use isset() to check the condition ?

推荐答案

对于函数的返回,请不要使用issetempty,因为它们仅对变量起作用,并且仅在此处测试可能不存在的变量变量而不会触发错误.

For returns from functions, you use neither isset nor empty, since those only work on variables and are simply there to test for possibly non-existing variables without triggering errors.

对于函数返回,检查变量是否存在是没有意义的,所以只需执行以下操作:

For function returns checking for the existence of variables is pointless, so just do:

if (!my_function()) {
    // function returned a falsey value
}

要详细了解此内容,请参见 PHP issetempty .

To read about this in more detail, see The Definitive Guide To PHP's isset And empty.

这篇关于PHP检查False还是Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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