is_int

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

is_int检测变量是否是整数

说明

is_int(mixed $value): bool

检测变量的类型是否为整数(integer)。

注意:

若想检测变量是否是数字或数字字符串(如表单输入,它们通常为字符串),则必须使用 is_numeric()

参数

value

要检测的变量。

返回值

如果 valueint,则返回 true,否则返回 false

范例

示例 #1 is_int() 示例

<?php
$values
= array(23, "23", 23.5, "23.5", null, true, false);
foreach (
$values as $value) {
echo
"is_int(";
var_export($value);
echo
") = ";
var_dump(is_int($value));
}
?>

以上例程会输出:

is_int(23) = bool(true)
is_int('23') = bool(false)
is_int(23.5) = bool(false)
is_int('23.5') = bool(false)
is_int(NULL) = bool(false)
is_int(true) = bool(false)
is_int(false) = bool(false)

参见

add a note

User Contributed Notes

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