When converted to Boolean, the following values are considered FALSE:
The Boolean value FALSE itself
The value of the integer 0 (0)
The floating-point value of 0.0 (0)
empty string, and string "0"
An array that does not include any elements
Objects that do not include any member variables (PHP 4.0 only applies)
Special type NULL (includes variables that have not yet been set)
SimpleXML object generated from an XML document that does not have any tags (tags)
All other values are considered TRUE (including any resources).
Warning
-1 and other non-0 values (whether positive or negative) are considered to be true!
Copy Code code as follows:
<?php
Var_dump ((BOOL) ""); BOOL (FALSE)
Var_dump ((bool) 1); BOOL (TRUE)
Var_dump ((BOOL)-2); BOOL (TRUE)
Var_dump ((bool) "foo"); BOOL (TRUE)
Var_dump ((bool) 2.3e5); BOOL (TRUE)
Var_dump ((BOOL) array (12)); BOOL (TRUE)
Var_dump ((bool) array ()); BOOL (FALSE)
Var_dump ((BOOL) "false"); BOOL (TRUE)
Boolean spin string when,true=>1,false=> "";