PHP is_numeric() 函数
PHP 教程
· 2019-01-31 19:12:59
is_numeric() 函数用于检测变量是否为数字或数字字符串。
PHP 版本要求:PHP 4, PHP 5, PHP 7
语法
bool is_numeric ( mixed $var )
参数说明:
- $var:要检测的变量。
返回值
如果指定的变量是数字和数字字符串则返回 TRUE,否则返回 FALSE。
实例
实例
$var_name1=678;
$var_name2="a678";
$var_name3="678";
$var_name4="codercto.com";
$var_name5=698.99;
$var_name6=array("a1","a2");
$var_name7=+125689.66;
if (is_numeric($var_name1))
{
echo "$var_name1 是数字" . PHP_EOL;
}
else
{
echo "$var_name1 不是数字" . PHP_EOL ;
}
if (is_numeric($var_name2))
{
echo "$var_name2 是数字" . PHP_EOL ;
}
else
{
echo "$var_name2 不是数字" . PHP_EOL ;
}
$result=is_numeric($var_name3);
echo "[ $var_name3 是数字吗? ]" .var_dump($result) . PHP_EOL;
$result=is_numeric($var_name4);
echo "[ $var_name4 是数字吗? ]" .var_dump($result) . PHP_EOL;
$result=is_numeric($var_name5);
echo "[ $var_name5 是数字吗? ]" .var_dump($result) . PHP_EOL;
$result=is_numeric($var_name6);
echo "[ $var_name6 是数字吗? ]" .var_dump($result) . PHP_EOL;
$result=is_numeric($var_name7);
echo "[ $var_name7 是数字吗? ]" .var_dump($result);
输出结果为:
678 是数字 a678 不是数字 bool(true) [ 678 是数字吗? ] bool(false) [ codercto.com 是数字吗? ] bool(true) [ 698.99 是数字吗? ] bool(false) [ Array 是数字吗? ] bool(true) [ 125689.66 是数字吗? ]
点击查看所有 PHP 教程 文章: https://codercto.com/courses/l/5.html
Spring Into HTML and CSS
Molly E. Holzschlag / Addison-Wesley Professional / 2005-5-2 / USD 34.99
The fastest route to true HTML/CSS mastery! Need to build a web site? Or update one? Or just create some effective new web content? Maybe you just need to update your skills, do the job better. Welco......一起来看看 《Spring Into HTML and CSS》 这本书的介绍吧!