PHP检查False还是Null

编程入门 行业动态 更新时间:2024-10-10 07:29:38
本文介绍了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 ?

推荐答案

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

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 isset和empty .

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

更多推荐

PHP检查False还是Null

本文发布于:2023-07-21 06:05:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1174848.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:PHP   False   Null

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!