What is the php string boolean type?

藏色散人
Release: 2023-03-17 20:36:02
Original
3647 people have browsed it

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".

What is the php string boolean type?

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.

Copy after login

Normally the bool value returned by the operator will be passed to the control flow.

\n";
}
// ...因为可以使用下面这种简单的方式:
if ($show_separators) {
    echo "
\n"; } ?>
Copy after login

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!

Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!