is_bool()是php中的內置函數。 is_bool()函數用於查找變量是否為布爾值。
用法:
boolean is_bool($variable_name) $variable_name:the variable we want to check.
返回值:這是一個布爾函數,因此當$variable_name是布爾值時返回TRUE,否則返回FALSE。
例子1:
<?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.';
?>
輸出:
Variable is a boolean. 32 is not a boolean.
例子2:
<?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.
?>
輸出:
1 1
參考:http://php.net/manual/en/function.is-bool.php
相關用法
注:本文由純淨天空篩選整理自sid4321大神的英文原創作品 PHP | is_bool()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。