Boolean type is the simplest type in PHP. Its value can be TRUE or FALSE.
For example:
$foo=false;
$foo1=true;
echo "When it is false, the output value is:".$foo; //There is no output value
echo "
is When true, the output value is: ".$foo1; //Output 1
Main details here:
When converted to boolean, the following values are considered FALSE:
1. the boolean value FALSE itself
2. the integer value 0 (zero)
3. The floating point value 0.0 (zero), the empty string, and the string "0"
4. An array that does not include any elements
5. Object that does not include any member variables (only applicable to PHP 4.0)
6. Special type NULL (including variables that have not been set)
7. SimpleXML object generated from XML document without any tags
//$a=0;
//$a=0.0;
$a="0";
var_dump((bool) 0);
echo "
";
var_dump((bool) array());
if($a==false){
echo "Empty 0 is converted to false by default, success! ";
}else {
echo "cannot be converted to false";
}
Output:
bool(false)
bool(false) Empty 0 is converted to false by default, success!