Introduction to the Boolean type of PHP data type

Source: Internet
Author: User
Tags type null
The Boolean type is the simplest type in PHP. It can have a value of TRUE or FALSE,

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

In Computer science, a Boolean data type, also known as a logical data type, is a primitive type with only two values: Non 0 (usually 1 or-1) and 0 (equivalent Yu Jin and false, respectively).

In some languages, a Boolean data type is defined to represent more than two truth values. For example, the ISO sql:1999 standard defines a SQL Boolean that can store three possible values: True, FALSE, unknown (SQL NULL is treated as an unknown truth value, but only used in Boolean type).

This data type is used in Boolean and other operations, such as with (and, &, *), or (or, |, +), XOR (XOR, Neqv, ^), equivalence (EQV, =, = =), and non (not, ~,!), which are consistent with logical algebra and arithmetic operations.

Such as:

$foo =false; $foo 1=true;echo "is false when the output value is:". $foo; No output value echo "<br/> is true when output value is:". $foo 1; Output 1

Here are the main details:

When converted to Boolean, the following values are considered FALSE:
1, the Boolean value FALSE itself
2, the integer value 0 (0)
3, the floating-point value 0.0 (0) empty string, and the string "0"
4. An array that does not include any elements
5. Objects that do not include any member variables (PHP 4.0 applies only)
6. Special type NULL (including variables not yet set)
7. SimpleXML object generated from an XML document that does not have any tags (tags)

$a =0;//$a =0.0; $a = "0"; Var_dump ((bool) 0); echo "<br/>"; Var_dump ((bool) array ()); if ($a ==false) {echo " Null 0 default conversion to FALSE, success! ";} Else{echo "cannot be converted to false";}

Output:

BOOL (FALSE)
BOOL (FALSE) NULL 0 default conversion to FALSE, success!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.