我有时会看到如下代码:
if(!Somefunction()){
// ...
}else{
// ...
}
Run Code Online (Sandbox Code Playgroud)
我更像是一个java开发人员,我知道上述语句的唯一方法就是函数最后返回true或false.
以这种格式使用的每个函数都必须返回true或false吗?或者这是否意味着功能是否成功执行?
不,不一定True或False.在PHP中,任何变量都可以转换为boolean.
转换为布尔值时,会考虑以下值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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |