Friday, February 6, 2026
HomeLanguagesPHP | is_bool()

PHP | is_bool()

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
//php code
$variable_name1 = false;
$variable_name2 = 32;
 
//$variable_name1 is boolean, gives TRUE
if (is_bool($variable_name1))
 
echo "Variable is a boolean. \n";
else
echo 'Variable is not a boolean. \n';
 
//$variable_name2 is boolean, gives FALSE
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
// PHP code
function square($num)
{
    return (is_bool($num));
}
echo square(TRUE) ."\n";   // outputs '1'.
echo square(FALSE) ."\n";   // outputs '1'.
echo square(56) ."\n";   // nothing is returned.
 
?>


Output:

1
1

Reference:http://php.net/manual/en/function.is-bool.php

Previous article
Next article
RELATED ARTICLES

Most Popular

Dominic
32491 POSTS0 COMMENTS
Milvus
126 POSTS0 COMMENTS
Nango Kala
6862 POSTS0 COMMENTS
Nicole Veronica
11987 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12075 POSTS0 COMMENTS
Shaida Kate Naidoo
6995 POSTS0 COMMENTS
Ted Musemwa
7237 POSTS0 COMMENTS
Thapelo Manthata
6947 POSTS0 COMMENTS
Umr Jansen
6933 POSTS0 COMMENTS