is_bool() is an inbuilt function in php. The is_bool() function is used to find whether a variable is a boolean or not.
Syntax:
boolean is_bool($variable_name)
$variable_name:the variable we want to check.
return value: It is a boolean function so returns TRUE when $variable_name is a boolean value, otherwise FALSE.
Example 1:
PHP
<?php
$variable_name1 = false;
$variable_name2 = 32;
if (is_bool($variable_name1))
echo "Variable is a boolean. \n";
else
echo 'Variable is not a boolean. \n';
if (is_bool($variable_name2))
echo '32 is a boolean.\n';
else
echo '32 is not a boolean.';
?>
|
Output:
Variable is a boolean.
32 is not a boolean.
Example 2:
PHP
<?php
function square($num)
{
return (is_bool($num));
}
echo square(TRUE) ."\n";
echo square(FALSE) ."\n";
echo square(56) ."\n";
?>
|
Output:
1
1
Reference:http://php.net/manual/en/function.is-bool.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Apr, 2023
Like Article
Save Article