Check if a variable is a boolean in PHP
Description
The following code shows how to check if a variable is a boolean.
Example
<?php//ww w .j a v a 2s. c o m
$a = false;
$b = 0;
// Since $a is a boolean, it will return true
if (is_bool($a) === true) {
echo "Yes, this is a boolean";
}
// Since $b is not a boolean, it will return false
if (is_bool($b) === false) {
echo "No, this is not a boolean";
}
?>
The code above generates the following result.