我有时会看到这样的代码:
if(!Somefunction()){
// ...
}else{
// ...
}
我更像是一名 Java 开发人员,我知道上述声明成立的唯一方式是函数最后返回 true 还是 false。
以这种格式使用的每个函数都必须返回 true 或 false 吗?还是说函数执行成功了?
最佳答案
不,不一定是 True
或 False
。在 PHP 中,任何变量都可以转换为 boolean .
当转换为 bool 值时,以下值被认为是False
:
the boolean FALSE itself
the integer 0 (zero)
the float 0.0 (zero)
the empty string, and the string "0"
an array with zero elements
an object with zero member variables (PHP 4 only)
the special type NULL (including unset variables)
SimpleXML objects created from empty tags
关于php - if 语句和函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27773845/