如果声明和功能

ala*_*udi 3 php web

我有时会看到如下代码:

if(!Somefunction()){
    // ...
}else{
    // ...
}
Run Code Online (Sandbox Code Playgroud)

我更像是一个java开发人员,我知道上述语句的唯一方法就是函数最后返回true或false.

以这种格式使用的每个函数都必须返回true或false吗?或者这是否意味着功能是否成功执行?

Sal*_*ali 7

不,不一定TrueFalse.在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)