Php: Explanation of boolean data type instances

Source: Internet
Author: User
Boolean is one of the PHP4 scalar data types. it is one of the more common data types in PHP. it can only save two values: true and false. It is case insensitive, so true is the same as TRUE. What is a boolean data type?

Boolean is one of the PHP4 scalar data types. it is one of the more common data types in PHP. it can only save two values: true and false. It is case insensitive, so true is the same as TRUE.

If we need to set a Boolean variable, we only need to assign the true or false values directly to the variable,

$a=true;$b=false;

Instance

Boolean variables are usually applied to expressions of conditional control or cyclic control statements. In the if condition control statement, check whether the value of $ boo is true. if it is true, the output "variable $ boo is true!" is displayed !", Otherwise, the output "variable $ boo is false !", The code is as follows:

 

Code running result:

Note: In PHP, not only boolean values are false, but in some special cases, non-boolean values are also considered false.

These special cases are: 0, 0.0, "0", blank string (""), only declare arrays without assignment, etc,The following are examples of these special cases:

1. when the value of the variable is an integer, if the value is 0, it is false, and other values are true.

 

2. if the value of the variable is floating-point, if the value is 0.00 (that is, only 0), it is false, and other values are true:

 

3. when the variable value is a string, if the value is "" (null) or 0 is false, the other values are true (even if there is a space in the middle of 0.00 or ):

 

4. when the variable is array type, if the array does not contain any member, it is false; otherwise, it is true.

 

The above is the general usage of booeanl data variables in PHP. In the next section, we will introduce "string" in the scalar data type )".

The above is php: detailed description of boolean data type instances. For more information, see other related articles in the first PHP community!

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.