If the statement and functions

Sometimes I see code that looks like this:

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

      

I'm more of a java developer and the only way I know what the above statement contains is if the function returns true or false at the end.

Any function that is used in this format must return true or false? Or does it mean what if the function succeeds?

+3


source to share


1 answer


No, not necessary True

or False

. In PHP, any variable can be converted to boolean .

When converted to a boolean value, they are considered values 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

      

+7


source







All Articles