Home  >  Article  >  Backend Development  >  Detailed explanation of Boolean types in PHP

Detailed explanation of Boolean types in PHP

零下一度
零下一度Original
2017-07-27 10:41:551917browse

1. FALSE of Boolean value

2. Integer value 0

3 Floating point value 0.000000...

4. Blank string and string "0" is also a false value

5. Empty array

6. Special type of TRUE

PS: In PHP4 and previous versions, empty objects are also false values.

The Boolean type is the simplest type in PHP. Its value can be TRUE or FALSE.

For example:

$foo=false;
$foo1=true;
echo "为假时输出值为:".$foo; //没有输出值
echo "<br />为真时输出值为:".$foo1; //输出1

The main details here:

When converted to boolean, the following values ​​​​are considered FALSE:
1. The Boolean value FALSE itself
2. The integer value 0 (zero)
3. The floating point value 0.0 (zero), the empty string, and the string "0"
4. An array that does not include any elements
5. Objects that do not include any member variables (only applicable to PHP 4.0)
6. Special type NULL (including variables that have not been set)
7. SimpleXML objects generated from XML documents without any tags (tags)

//$a=0;//$a=0.0;$a="0";var_dump((bool) 0);echo "<br />";var_dump((bool) array());if($a==false){echo "空0默认转换为false,成功!";}else{echo "不能转换为false";}
输出:
bool(false) bool(false) 空0默认转换为false,成功!

The above is the detailed content of Detailed explanation of Boolean types in PHP. 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