Home > Backend Development > PHP Tutorial > Detailed explanation of boolean (Boolean) type in php_PHP tutorial

Detailed explanation of boolean (Boolean) type in php_PHP tutorial

WBOY
Release: 2016-07-13 10:25:40
Original
963 people have browsed it

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

the Boolean value FALSE itself

the integer value 0 (zero)

the floating point value 0.0 (zero)

Empty string, and string "0"

Array containing no 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 set)

SimpleXML object generated from an XML document without any tags

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

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

Copy code The code is as follows:

var_dump((bool) ""); bool(false)
var_dump((bool) 1);    // bool(true)
var_dump((bool) -2);    / /  bool(true)
var_dump((bool) “foo” ); // bool(true)
var_dump((bool) 2.3e5); // bool(true)
var_dump((bool) array(12)); // bool(true)
var_dump ((bool) array()); // bool(false)
var_dump((bool) "false"); // bool(true) 

When converting Boolean to string, true =>1,false=>"";

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/824983.htmlTechArticleWhen converted to boolean, the following values ​​are considered FALSE: the boolean value FALSE itself the integer value 0 ( zero) the floating point value 0.0 (zero) the empty string, and the string "0" does not include any...
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 admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template