Finds whether a variable is a number or a numeric string.
PHP is_numeric() function has the following syntax.
bool is_numeric ( mixed $var )
Returns TRUE if var is a number or a numeric string, FALSE otherwise.
Is it a numeric value?
<?php/* w ww. j a v a2 s. com*/
$tests = array(
"4",
12,
0x29,
0124,
0b111001,
137e0,
"not numeric",
array(),
9.1
);
foreach ($tests as $element) {
if (is_numeric($element)) {
echo "'{$element}' is numeric", PHP_EOL;
} else {
echo "'{$element}' is NOT numeric", PHP_EOL;
}
}
?>
The code above generates the following result.