在php中,为什么empty("0")返回true? [英] in php, why empty("0") returns true?
本文介绍了在php中,为什么empty("0")返回true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
根据php文档,调用empty($var)
According to php documentation, the following expressions return true when calling empty($var)
- "(一个空字符串)
- 0(0为整数)
- 0.0(浮点数为0)
- "0"(0作为字符串)
- NULL
- 假
- array()(一个空数组)
- $ var; (已声明变量,但没有值)
- "" (an empty string)
- 0 (0 as an integer)
- 0.0 (0 as a float)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- $var; (a variable declared, but without a value)
我已经找到了如何通过使用empty($var) && $var != 0
解决"问题的方法,但是为什么php开发人员做到了呢?
我认为这很荒谬,请支持以下代码:
i've found how to "solve" the problem by using empty($var) && $var != 0
but why php developers did it?
i think it is ridiculous, suppouse you have this code:
if (empty($_POST["X"])) {
doSomething();
}
我认为"0"
不为空,什么也没有时为空!!!
也许最好使用
i think "0"
is not empty, empty is when there is nothing!!!
maybe it's better to use
if (isset($x) && x != "") {//for strings
doSomething();
}
推荐答案
查看全文