Home > Backend Development > PHP Tutorial > Introduction to Boolean data types in PHP_PHP Tutorial

Introduction to Boolean data types in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 15:11:20
Original
952 people have browsed it

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

For example:

$foo=false;
$foo1=true;
echo "When it is false, the output value is:".$foo; //There is no output value
echo "
is When true, the output value is: ".$foo1; //Output 1

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. Object that does not include any member variables (only applicable to PHP 4.0)
6. Special type NULL (including variables that have not been set)
7. SimpleXML object generated from XML document without any tags

//$a=0;
//$a=0.0;
$a="0";
var_dump((bool) 0);
echo "
";
var_dump((bool) array());
if($a==false){
echo "Empty 0 is converted to false by default, success! ";
}else {
echo "cannot be converted to false";
}

Output:

bool(false)
bool(false) Empty 0 is converted to false by default, success!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/326910.htmlTechArticleBoolean type is the simplest type in PHP. Its value can be TRUE or FALSE. For example: $foo=false; $foo1=true; echo "When it is false, the output value is:".$foo; //There is no output value echo "br /When it is true...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template