Home>Article>Backend Development> What is the php string boolean type?
php String Boolean type refers to the Boolean Boolean type. bool has only two values, which are used to express true values, either true or false. To specify a Boolean type, you can use the constant true or false, and its setting The syntax is "$foo = True;", which means setting "$foo" to "TRUE".
The operating environment of this tutorial: Windows 10 system, PHP version 8.1, DELL G3 computer
What is the Boolean type of php string ?
Boolean Boolean type
bool has only two values, used to express the truth value, either true or false.
Syntax
To specify a bool, use the constant true or false. Both are not case sensitive.
Normally the bool value returned by the operator will be passed to the control flow.
\n"; } // ...因为可以使用下面这种简单的方式: if ($show_separators) { echo "
\n"; } ?>
Convert to Boolean
To explicitly convert a value to bool, you can use (bool) cast. Normally this is not necessary because the value will automatically be interpreted as a bool value when used in a logical context. Please read the Type Conversion page for more information.
See the identification of type conversion.
When converted to bool, the following values are considered false:
The Boolean value false itself
Integer value 0 (zero)
Floating point value 0.0 (zero)-0.0 (zero)
Empty string "", and string "0"
An array that does not include any elements
Unit type NULL (including variables that have not been assigned a value)
The coercion behavior of internal objects is overloaded as bool. For example: a SimpleXML object created from an empty element with no attributes.
All other values are considered true (including resources and NAN).
Warning:
-1, like other non-zero values (positive or negative), is considered true!
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What is the php string boolean type?. For more information, please follow other related articles on the PHP Chinese website!