PHP: Boolean
True and False
true
and false
are built-in boolean type. Case does not matter. true
is the same as True
.
The following are all FALSE:
- the integer
0
(zero) - the float
0.0
(zero) - the empty string
""
, and the string"0"
- array with zero elements
- object with zero member variables (PHP 4 only)
- the special type
NULL
(including unset variables) - SimpleXML objects created from empty tags
Example:
<?php $x = 4; if ($x == 4) {echo "yay";} else {echo "nay";} # yay if (true) {echo "yay";} else {echo "nay";} # yay if (trUe) {echo "yay";} else {echo "nay";} # yay ?>