is_bool

(PHP 4, PHP 5)

is_bool --  检测变量是否是布尔型

描述

bool is_bool ( mixed var )

如果 varboolean 则返回 TRUE

例子 1. is_bool() 示例

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

// 因为 $a 是布尔型,所以结果为真
if (is_bool($a)) {
    print
"Yes, this is a boolean";
}

// 因为 $b 不是布尔型,所以结果为非真
if (is_bool($b)) {
    print
"Yes, this is a boolean";
}
?>

参见 is_array()is_float()is_int()is_integer()is_string()is_object()


add a note add a note User Contributed Notes
21-Apr-2006 07:12
Small caveat to rh's post: back in PHP 3, "0" would be considered non-empty (i.e., empty would return false), even though (bool) on "0" would also evaluate to false; thus, they would not be complete opposites for someone using PHP 3.
rh at richardhoward dot net
23-May-2005 02:17
punkpuke is wrong here; what he means to say is that empty($x) is the opposite of (bool)$x.  is_bool($x) returns true where $x === false.