• PHP Video Tutorials

PHP - is_bool() Function



Definition and Usage

The function is_bool() checks whether the variable is boolean or not.

Syntax

bool is_bool ( mixed $value )

Parameters

Sr.No Parameter & Description
1

value

The variable being evaluated.*mixed: mixed indicates that a parameter may accept multiple (but not necessarily all) types

Return Values

This function returns true if the variable is boolean, else false.

Dependencies

PHP 4 and above

Example

Following example demonstrates use of is_bool() function −

<?php
   $bool1 = true;
   $bool2 = false;
   $bool3 = 0;
   $bool4 = 1;

   echo "bool1 is ".(is_bool($bool1)?'boolean':'not boolean')."<br>";
   echo "bool2 is ".(is_bool($bool2)?'boolean':'not boolean')."<br>";
   echo "bool3 is ".(is_bool($bool3)?'boolean':'not boolean')."<br>";
   echo "bool4 is ".(is_bool($bool4)?'boolean':'not boolean')."<br>";
?>

Output

This will produce following result −

bool1 is boolean
bool2 is boolean
bool3 is not boolean
bool4 is not boolean
php_variable_handling_functions.htm
Advertisements