当从函数返回时,如何检查变量是否为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
发布评论