The is_bool Function
The is_bool
function checks whether the passed value is
of boolean type (true or false). The function returns true
,
if the value is boolean, and false
otherwise.
The function accepts one parameter - the value to check.
Syntax
is_bool(mixed $value): bool
Example
Let's check several values for belonging to the boolean type:
<?php
$res1 = is_true;
$res2 = is_false;
$res3 = is_bool(1);
$res4 = is_bool('true');
var_dump($res1, $res2, $res3, $res4);
?>
Code execution result:
true
true
false
false
Example
Let's check variables of different types:
<?php
$boolVar = false;
$intVar = 0;
$strVar = 'false';
var_dump(
is_bool($boolVar),
is_bool($intVar),
is_bool($strVar)
);
?>
Code execution result:
true
false
false