PHP is_numeric
function is used to detect whether a variable is a number or a numeric string.
Syntax
is_numeric (mixed $var)
Return value
Returns TRUE if the specified variable is a number and a numeric string, otherwise returns FALSE .
Example
$var_name1 = 678; $var_name2 = "a678"; $var_name3 = "678"; $var_name4 = "runoob.com"; $var_name5 = 698.99; $var_name6 = array("a1", "a2"); $var_name7 = +125689.66; $var_name8 = -125689.66; if(is_numeric($var_name1)) echo '$var_name1 true'; if(is_numeric($var_name2)) echo '$var_name2 true'; if(is_numeric($var_name3)) echo '$var_name3 true'; if(is_numeric($var_name4)) echo '$var_name4 true'; if(is_numeric($var_name5)) echo '$var_name5 true'; if(is_numeric($var_name6)) echo '$var_name6 true'; if(is_numeric($var_name7)) echo '$var_name7 true'; if(is_numeric($var_name8)) echo '$var_name8 true'; //输出:$var_name1 true$var_name3 true$var_name5 true$var_name7 true$var_name8 true
It can be seen from the above example that returning 1, 3, 5, 7, and 8 all returns true, indicating that others return false
Recommended tutorial: " PHP video tutorial》
The above is the detailed content of PHP uses is_numeric instance parsing. For more information, please follow other related articles on the PHP Chinese website!