Details about the PHP Boolean

Source: Internet
Author: User
Recently, I prefer to pick up the details, because these details are very helpful for code writing and bug finding, and can greatly improve the speed of project development.

Talk less, we begin to explain PHP Boolean.

First, the Boolean type is the basic data type of PHP, which is either true or false. Uppercase and lowercase are not differentiated.

If you need to convert other types to type bool, you can use (bool) or (Boolean) to convert.

Such as

echo true = = = (BOOL) -1;echo true = = = (Boolean) -1;echo true = = = (Boolean)-1;

Public Function Test_true () {$this->asserttrue ( -1 = = true);//-1=> true$this->asserttrue ("false" = = true);//"F Alse "= = True$this->asserttrue (" null "= = TRUE);  "Null" =  true$this->asserttrue ("0.0" = = true);   "0.0"   = True$this->asserttrue ((bool)-1), $this->asserttrue ((Boolean)-1); $this->asserttrue ( Boolean)-1);} Public Function Test_false () {$this->asserttrue (null = = False);//null = false$this->asserttrue (0 = = false); 
  //0 = false$this->asserttrue (0.0 = = false); 0.0 = False$this->asserttrue ("" = = False);  "" = = False$this->assertfalse ("" = = False); "" = true}

These are the two simple test cases that I wrote. All of them asserted success.

-1 = = True results are true.

Similarly, NULL = = False results are also true.

is the non-strict type of comparison.

There's also a need to be aware of bool, Boolean, Boolean. In fact, there should be no big difference. But always keep in mind that it's just the basic data type, and there's no class concept ...

  • 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.