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.
is_bool
(PHP 4, PHP 5)
is_bool — 変数が boolean であるかを調べる
説明
bool is_bool ( mixed $var )指定した変数が boolean であるかどうかを調べます。
パラメータ
- var
評価する変数。
返り値
var が boolean である場合に TRUE 、それ以外の場合に FALSE を返します。
例
例 2484. is_bool() の例
<?php
$a = false;
$b = 0;
// $a は boolean なので、これは true です
if (is_bool($a)) {
echo "Yes, this is a boolean";
}
// $b は boolean ではないので、これは true ではありません
if (is_bool($b)) {
echo "Yes, this is a boolean";
}
?>
参考
| is_float() |
| is_int() |
| is_string() |
| is_object() |
| is_array() |
is_bool
21-Apr-2006 08:12
rh at richardhoward dot net
23-May-2005 03:17
23-May-2005 03: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.