Introduction to Boolean type in PHP

Source: Internet
Author: User
Tags type null
Introduction to Boolean type in PHP

  1. $ Foo = false;
  2. $ Foo1 = true;
  3. When echo "is false, the output value is:". $ foo; // no output value
  4. Echo"
    If it is true, the output value is: ". $ foo1; // output 1

Note: When converting to boolean, the following values are considered FALSE: 1. the boolean value is FALSE itself. 2. the integer value is 0 (0) 3. the floating point value 0.0 (0) is an empty string and the string "0" 4. an array that does not include any elements 5. an object that does not include any member variables (applicable only to PHP 4.0) 6. Special type NULL (including unset variables) 7. SimpleXML object generated from XML documents without any tags

Example:

  1. // $ A = 0;
  2. // $ A = 0.0;
  3. $ A = "0 ";
  4. Var_dump (bool) 0 );
  5. Echo"
    ";
  6. Var_dump (bool) array ());
  7. If ($ a = false ){
  8. Echo "null 0 is converted to false by default. success! ";
  9. } Else {
  10. Echo "cannot be converted to false ";
  11. }

Output result:

Bool (false) null 0 is converted to false by default. 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.