<?php
$foo = True; // assign the value TRUE to $foo
?>
<?php
// == is an operator which tests
// equality and returns a boolean
if ($action == "show_version") {
echo "The version is 1.23";
}
// this is not necessary...
if ($show_separators == TRUE) {
echo "<hr>\n";
}
// ...because this can be used with exactly the same meaning:
if ($show_separators) {
echo "<hr>\n";
}
?>
-
This is the simplest type.
-
Expresses a truth value.
-
It can be either TRUE or FALSE.
-
To specify a boolean literal, use the constants TRUE or FALSE. Both are case-insensitive.
-
Typically, the result of an operator which returns a boolean value is passed on to a control structure.
Converting to boolean
To explicitly convert a value to boolean, use the (bool) or (boolean) casts.
In most cases the cast is unnecessary, since a value will be automatically converted if an operator, function or control structure requires a boolean argument.