English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
is_numeric() The function is used to check whether a variable is a number or a numeric string.
PHP version requirement: PHP 4, PHP 5, PHP 7
bool is_numeric ( mixed $var )
Parameter description:
If the specified variable is a number or a numeric string, it returns TRUE; otherwise, it returns FALSE.
<?php $var_name1=678; $var_name2="a678"; $var_name3="678"; $var_name4="oldtoolbag.com"; $var_name5=698.99; $var_name6=array("a1","a2"); $var_name7=+125689.66; if (is_numeric($var_name1)) { echo "$var_name1 Is a number" . PHP_EOL; } else { echo "$var_name1 Not a number" . PHP_EOL ; } if (is_numeric($var_name2)) { echo "$var_name2 Is a number" . PHP_EOL ; } else { echo "$var_name2 Not a number" . PHP_EOL ; } $result=is_numeric($var_name3); echo "[ $var_name3 Is it a number? ]" .var_dump($result) . PHP_EOL; $result=is_numeric($var_name4); echo "[ $var_name4 Is it a number? ]" .var_dump($result) . PHP_EOL; $result=is_numeric($var_name5); echo "[ $var_name5 Is it a number? ]" .var_dump($result) . PHP_EOL; $result=is_numeric($var_name6); echo "[ $var_name6 Is it a number? ]" .var_dump($result) . PHP_EOL; $result=is_numeric($var_name7); echo "[ $var_name7 Is it a number? ]" .var_dump($result); ?>
The output result is:
678 Is a number a678 Not a number bool(true) [ 678 Is it a number? ] bool(false) [ oldtoolbag.com Is it a number? ] bool(true) [ 698.99 Is it a number? ] bool(false) [ Array Is it a number? ] bool(true) [ 125689.66 Is it a number? ]