if 语句和函数

if statement and functions

我有时会看到这样的代码:

if(!Somefunction()){
    // ...
}else{
    // ...
}

我更像是一名 java 开发人员,我知道上述陈述成立的唯一方法是函数 return 最后是真还是假。

以这种格式使用的每个函数是否都必须 return 为真或假?还是说函数执行成功了?

不,不一定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