Php Boolean data type and process-controlled data type conversion Boolean data type is the simplest data type. It can be TRUE or FALSE, and keywords are case-insensitive. To explicitly convert an & #20540; to a boolean type, use (bool) or (boolean) to force the conversion. Php performs automatic type conversion in many cases, especially when calculating conditional expressions of flow control statements. When converted to Boolean & #20540;, the following & #20540; is considered to be the f php Boolean data type and the data type conversion controlled by the process
Boolean is the simplest data type. It can be TRUE or FALSE, and keywords are case-insensitive.
To explicitly convert a value to a boolean type, use (bool) or (boolean) to force the conversion. Php performs automatic type conversion in many cases, especially when calculating conditional expressions of flow control statements.
When converted to a Boolean value, the following values are considered false:
1) Boolean value false;
2) integer value 0 (0 );
3) floating point value: 0.0 (zero );
4) blank string and string "0 ";
5) arrays without member variables;
6) objects without cells (applicable only to PHP4 );
7) Special type NULL (including unset variables );
In addition, all other values are considered to be true (including any resources ).
You can use the following program example for testing:
During development, you must pay attention to the hidden danger of default conversion of Boolean values when determining conditions.
The following questions are about this:
"; If (" 0 ") echo" true "; elseecho" false-2 "."
"; If ($ I) echo" true "; elseecho" false-3 "."
"; If (" false ") echo" true "; elseecho" false-4 "."
"; If (false) echo" true "; elseecho" false-5 "."
"; If (0.0) echo" true "; elseecho" false-6 "."
"; If (php) echo" true "; elseecho" false-7 "."
"; If (" ") echo" true "; elseecho" false-8 "."
"; If (null) echo" true "; elseecho" false-9 "."
"; If (array (12) echo" true "; elseecho" false-10 "."
"; If (array () echo" true "; elseecho" false-11 "."
";/* Output result: false-1false-2false-3true false-5false-6true false-8false-9true false-11 analysis: if statements return false when the condition does not meet (that is, the conditional expression evaluates to false. Php's if statement does not have then and has elseif (the same as else if). when it is converted to boolean, the following values are considered false: 1) boolean values false; 2) integer value 0 (0); 3) floating point value 0.0 (0); 4) blank string and string "0"; 5) array without member variables; 6) objects without cells (applicable only to PHP4); 7) special types of NULL (including unset variables); */?>