Home > Backend Development > PHP Tutorial > Bool value in PHP_PHP tutorial

Bool value in PHP_PHP tutorial

WBOY
Release: 2016-07-13 17:42:21
Original
1014 people have browsed it

In PHP, when other type variables are converted to boolean, the following value is considered FALSE:

Boolean value FALSE itself;
Integer value 0 (zero);
Floating point value 0.0 (zero);
Empty string (""), and string ("0") ;
An array that does not contain any elements;
An object that does not contain any member variables (only applicable to PHP 4.0);
The special type NULL (including variables that have not been set);
Never has any tags SimpleXML object generated from an XML document (tags);
All other values ​​are considered TRUE (including any resources).

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

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)
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486078.htmlTechArticleIn PHP, when other type variables are converted to boolean, the following values ​​are considered FALSE: Boolean value FALSE itself; The integer value 0 (zero); the floating point value 0.0 (zero); the empty string (""), and the characters...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template