Introduction to Boolean data types in PHP

怪我咯
Release: 2023-03-13 16:12:01
Original
3129 people have browsed it

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

1 is true (true), 0 is false (false)

In computer science, the Boolean data type is also known as It is a logical data type, a primitive type with only two values: non-zero (usually 1 or -1) and zero (equivalent to true and false respectively).

In some languages, the Boolean data type is defined to represent more than two truth values. For example, the ISO SQL:1999 standard defines a SQL Boolean type that can store three possible values: true, false, and unknown (SQL null is treated as an unknown true value, but only for use with Boolean types).

This data type is used in Boolean and other operations, such as AND (AND, &, *), or (OR, |, +), XOR (xor, NEQV, ^), equivalent to ( EQV, =, ==) and not (NOT, ~, !), which are consistent with logical algebra and arithmetic operations.

For example:

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

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 typevalue 0.0 (zero) emptyString, and the string "0"
4. Array not including any elements
5. Not including any membersVariableObject (only applicable to PHP 4.0)
6. Special type NULL (including variables that have not been set)
7. From SimpleXML object generated from an XML document without any 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";
}
Copy after login

Output:

bool(false)
bool(false) Empty 0 The default conversion is false, success!

The above is the detailed content of Introduction to Boolean data types in PHP. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!