Home > Backend Development > PHP Tutorial > Introduction to Boolean types in PHP

Introduction to Boolean types in PHP

WBOY
Release: 2016-07-25 08:57:47
Original
1217 people have browsed it
  1. $foo=false;
  2. $foo1=true;
  3. echo "When it is false, the output value is:".$foo; //There is no output value
  4. echo "
    When it is true, the output value For: ".$foo1; //Output 1
Copy the code

Some details to pay attention to: When converted to boolean, the following values ​​are considered FALSE: 1. the Boolean value FALSE itself 2. the integer value 0 (zero) 3. The floating point value 0.0 (zero), the empty string, and the string "0" 4. Array not containing any elements 5. Objects that do not include any member variables (only applicable to PHP 4.0) 6. Special type NULL (including variables that have not been set) 7. SimpleXML objects 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 "Empty 0 is converted to false by default, successful! ";
  9. }else{
  10. echo "cannot be converted to false ";
  11. }
Copy the code

Output results:

bool(false) bool(false) Empty 0 is converted to false by default, success!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template