<?php
$tests = array(
"42",
1337,
0x539,
02471,
0b10100111001,
1337e0,
"not numeric",
array(),
9.1,
null
);
foreach ($tests as $element) {
if (\is_numeric($element)) {
$int = (int) $element;
echo var_export($int, true) . " is numeric", PHP_EOL;
$float = (float) ($element * 10);
echo var_export($float, true) . " is numeric", PHP_EOL;
} else {
echo var_export($element, true) . " is NOT numeric", PHP_EOL;
}
}
preferences:
29.47 ms | 402 KiB | 5 Q