In this article, you will learn how to check if a variable is of boolean type in PHP. The is_bool() function in PHP checks whether a variable is a boolean or not. This function returns true (1) if the variable is a boolean, otherwise, it returns false/nothing.
what is the syntax of the IS_BOOL() function in php?
is_bool(variable);
Parameter | Description |
---|---|
variable | Required. Specifies the variable to check |
examples of the IS_BOOL() function
Example 1. In this example, we check whether a variable is a boolean or not.
<?php
$a = 1;
echo "a is " . is_bool($a) . "<br>";
$b = 0;
echo "b is " . is_bool($b) . "<br>";
$c = true;
echo "c is " . is_bool($c) . "<br>";
$d = false;
echo "d is " . is_bool($d) . "<br>";
?>