I sometimes see code that looks like this:
if(!Somefunction()){
// ...
}else{
// ...
}
I am more of a java developer and the only way I know the above statement holds is if the function returns a true or false at the end.
Does every function that is used in this format have to return a true or false? Or does this mean if the function is successfully executed?
No, not necessarily True or False. In PHP any variable can be converted to boolean.
When converting to boolean, the following values are considered 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With