Introduction to Boolean type in PHP
- $ Foo = false;
- $ Foo1 = true;
- When echo "is false, the output value is:". $ foo; // no output value
- Echo"
If it is true, the output value is: ". $ foo1; // output 1
Note: When converting to boolean, the following values are considered FALSE: 1. the boolean value is FALSE itself. 2. the integer value is 0 (0) 3. the floating point value 0.0 (0) is an empty string and the string "0" 4. an array that does not include any elements 5. an object that does not include any member variables (applicable only to PHP 4.0) 6. Special type NULL (including unset variables) 7. SimpleXML object generated from XML documents without any tags Example:
- // $ A = 0;
- // $ A = 0.0;
- $ A = "0 ";
- Var_dump (bool) 0 );
- Echo"
";
- Var_dump (bool) array ());
- If ($ a = false ){
- Echo "null 0 is converted to false by default. success! ";
- } Else {
- Echo "cannot be converted to false ";
- }
Output result: Bool (false) null 0 is converted to false by default. success! |