PHP - is_bool() 函式



定義和用法

is_bool() 函式檢查變數是否為布林值。

語法

bool is_bool ( mixed $value )

引數

序號 引數及描述
1

要評估的變數。*mixed:mixed 表示引數可以接受多種(但不一定是所有)型別

返回值

如果變數是布林值,則此函式返回true,否則返回false

依賴項

PHP 4 及以上版本

示例

以下示例演示了 is_bool() 函式的使用:

<?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>";
?>

輸出

這將產生以下結果:

bool1 is boolean
bool2 is boolean
bool3 is not boolean
bool4 is not boolean
php_variable_handling_functions.htm
廣告