is_bool

(PHP 4, PHP 5, PHP 7, PHP 8)

is_bool 检测变量是否是布尔值

说明

is_bool(mixed $value): bool

检查变量是否为布尔值。

参数

value

要检查的变量。

返回值

如果 value 是布尔值则返回 true,否则返回 false

范例

示例 #1 is_bool() 示例

<?php
$a
= false;
$b = 0;

// 因为 $a 是布尔值,所以结果为 true
if (is_bool($a) === true) {
echo
"Yes, this is a boolean";
}

// 因为 $b 不是布尔值,所以结果为 false
if (is_bool($b) === false) {
echo
"No, this is not a boolean";
}
?>

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top