A Boolean state is a state that has two values either high or low which means it contains 1 or 0. In programming, they are known as TRUE or FALSE

Syntax for Boolean type:

<?php
    $Boolean1 = true;
    $Boolean2 = false;
?>

When converting to Boolean type from another data type, use (BOOLEAN), the following values are considered FALSE:

  • the boolean FALSE itself
  • the integer 0 (zero)
  • the float 0.0 (zero)
  • the empty string, and the string "0"
  • an array with zero elements
  • an object with zero member variables (PHP 4 only)
  • the special type NULL (including unset variables)
  • SimpleXML objects created from empty tags

Every other value is considered to be TRUE including -1.

Example of a Boolean data type

 

›› go to examples ››