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!