is_integer
is_int 的别名
is_integer()
函数检查变量是否为整数类型。
该函数是 is_int()
的别名。
检查变量是否为整数类型:
<?php $a = 32; echo "a is " . is_integer($a) . "<br>"; $b = 0; echo "b is " . is_integer($b) . "<br>"; $c = 32.5; echo "c is " . is_integer($c) . "<br>"; $d = "32"; echo "d is " . is_integer($d) . "<br>"; $e = true; echo "e is " . is_integer($e) . "<br>"; $f = "null"; echo "f is " . is_integer($f) . "<br>"; ?>
亲自试一试
在 PHP 中,布尔值 true
和字符串 "32"
都不是整数类型,即使字符串包含数字也是如此。所以,对于 $d
和 $e
的检查将返回 FALSE
。同样地,$f
是一个字符串,尽管它的内容是 "null"
,但它也不是整数类型,所以检查也会返回 FALSE
。而浮点数如 $c
显然也不是整数,因此 is_int($c)
同样会返回 FALSE
。
is_integer(variable);
参数 | 描述 |
---|---|
variable | 必需。指定要检查的变量。 |