Php - Boolean

> Procedural Languages > Php

1 - About

3 - Management

3.1 - Assignment

  • Boolean non-sensitive constant (True and False)
$foo = True;
Advertising

3.2 - Explicit Conversion

  • Text Boolean
// the empty string, and the string "0" are false
(bool)('') = false;
(bool)('Some text') = true;
  • Number Boolean
// the integer 0 (zero) and the float 0.0 (zero)  are false
(bool)(0) = false;
(bool)(-1) = true;
(bool)(1) = true;
(bool)(2) = true;

The following element are considered as false (other cases are true)

  • 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