Home >Backend Development >PHP Problem >PHP determines whether a string is a number
php determines whether a string is a number
is_numeric() function is used to detect whether a variable is a number or a number String.
PHP version requirements: PHP 4, PHP 5, PHP 7
Syntax
bool is_numeric ( mixed $var )
Parameter description:
$var: The variable to be tested.
Return value
Returns TRUE if the specified variable is a number or numeric string, otherwise returns FALSE.
Example:
<?php $var_name1=678; if (is_numeric($var_name1)) { echo "$var_name1 是数字" . PHP_EOL; } else { echo "$var_name1 不是数字" . PHP_EOL ; }
Output:
678 是数字
For more PH related P knowledge, please visit PHP Chinese website!
The above is the detailed content of PHP determines whether a string is a number. For more information, please follow other related articles on the PHP Chinese website!