Thursday, 11 March 2021

php: is_bool: check variable holds Boolean value or not

Signature

is_bool ( mixed $value ) : bool

 

Description

Finds out whether a variable is a boolean or not. Returns true if value is a bool, false otherwise.

 

boolean_variable_check_demo.php

#!/usr/bin/php

<?php

   $var1 = true;
   $var2 = 123;

   echo "\n\$var1 : ";
   var_dump($var1);

   echo "\$var2 : $var2";

   echo "\n\nis \$var1 boolean : ";
   var_dump(is_bool($var1));

   echo "\nis \$var2 boolean : ";
   var_dump(is_bool($var2));
?>

Output

$./boolean_variable_check_demo.php 


$var1 : bool(true)
$var2 : 123

is $var1 boolean : bool(true)

is $var2 boolean : bool(false)




 

  

Previous                                                    Next                                                    Home

No comments:

Post a Comment