is_numeric
检测变量是否为数字或数字字符串
is_numeric()
函数用于检查变量是否为数字或数字字符串。
如果变量是数字或数字字符串,则此函数返回 true
(1),否则返回 false
/无返回值。
检查变量是否为数字或数字字符串:
<?php $a = 32; echo "a is " . is_numeric($a) . "<br>"; $b = 0; echo "b is " . is_numeric($b) . "<br>"; $c = 32.5; echo "c is " . is_numeric($c) . "<br>"; $d = "32"; echo "d is " . is_numeric($d) . "<br>"; $e = true; echo "e is " . is_numeric($e) . "<br>"; $f = null; echo "f is " . is_numeric($f) . "<br>"; ?>
亲自试一试
is_numeric(variable);
参数 | 描述 |
---|---|
variable | 必需。指定要检查的变量。 |