Ref: http://php.net/manual/en/function.is-numeric.php.
Example #1 is_numeric().
Why does the Example #1 routine output 1337 4 times instead of 1 time? My expectation is the routine would ouput the other 3 numeric values that follow 1337. Even if I re-arrange the order of the elements it still outputs 1337 4 times. I understand hex and binary values are not allowed, but why does the routine output 1337 for those values. Also, if I change 1337 to 01337 the ouput is 735.
Why these confusing outputs?
<?php
$tests = array(
"42", 1337, 0x539, 02471, 0b10100111001, 1238.443e2, "not numeric",
array(), 9.1, null
);
foreach ($tests as $element) {
if (is_numeric($element)) {
echo var_export($element, true) . " is numeric", PHP_EOL;
} else {
echo var_export($element, true) . " is NOT numeric", PHP_EOL;
}
}
?>
Output:
'42' is numeric
1337 is numeric
1337 is numeric
1337 is numeric
1337 is numeric
123844.300000000002910383045673370361328125 is numeric
'not numeric' is NOT numeric
array () is NOT numeric
9.0999999999999996447286321199499070644378662109375 is numeric
NULL is NOT numeric