In this PHP tutorial, you shall learn about the Boolean datatype, the boolean values, and how to use boolean values in PHP programs, with the help of examples.

Boolean in PHP

PHP Boolean value could be either TRUE or FALSE.

TRUE and FALSE are constants that you can assign to a PHP Variable.

<?php
$a = TRUE;
$b = FALSE;
?>

A boolean value can be used to write decision making statements.

Examples

ADVERTISEMENT

1. Boolean value in IF statement

You can use boolean value in if statement, in place of condition.

PHP Program

<?php
$a = TRUE;
$b = FALSE;

if ($a) {
    echo "a is TRUE. <br>";
} else {
    echo "a is FALSE. <br>";
}

if ($b) {
    echo "b is TRUE. <br>";
} else {
    echo "b is FALSE. <br>";
}
?>

Output

PHP Boolean

Conclusion

In this PHP Tutorial, we learned what a PHP Boolean datatype is, what values can it take, and how to use it in conditional expressions, etc.