Introduction to the Boolean type of PHP data type _php Example

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.

Such as:

$foo =false;
$foo 1=true;
echo "is false when the output value is:". $foo; No output value
echo "<br/> is true when the 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 of 0 (0)
3, the floating-point value of 0.0 (0) empty string, and the string "0"
4, does not include any elements of the array
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 objects generated from XML documents without 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 is converted to False by default, successful!" ";
}else{
echo "cannot be converted to false";
}

Output:

BOOL (FALSE)
BOOL (FALSE) NULL 0 the default conversion to FALSE, successful!

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.