Home  >  Article  >  Backend Development  >  Parsing the Boolean type of PHP data type (Boolean)

Parsing the Boolean type of PHP data type (Boolean)

怪我咯
怪我咯Original
2017-04-05 10:37:051444browse

This is the simplest type. boolean expresses a truth value and can be TRUE or FALSE.

Syntax

To specify a Boolean value, use the keywords TRUE or FALSE. Both are not case sensitive.

Usually the boolean 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 boolean, use (bool) or (boolean) to cast. But in many cases, casting is not necessary because when an operator, function, or flow control structure requires a boolean parameter, the value is automatically converted.

See the identification of type conversion.

When converted to boolean, the following values ​​are considered FALSE:

  • Boolean value FALSE itself

  • Integer value 0 (zero)

  • Floating point value 0.0 (zero)

  • The empty string, and the string "0"

  • An array that does not include any elements

  • An object that does not include any member variables (only applicable to PHP 4.0)

  • Special type NULL (including variables that have not been assigned a value)

  • SimpleXML objects generated from XML documents without any tags

All All other values ​​are considered TRUE (including any resources).

Warning

-1, like other non-zero values ​​(positive or negative), is considered TRUE!


The above is the detailed content of Parsing the Boolean type of PHP data type (Boolean). For more information, please follow other related articles on the PHP Chinese website!

Statement:
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 admin@php.cn