$f=1.0;
print(is_numeric($f)); // outputs 1, $f is a float
$i=1;
print(is_numeric($i)); // outputs 1, $i is an int
$nns="cool";
print(is_numeric($nns)); // outputs 0, $nns is a non-numeric string
$ns="-1.5";
print(is_numeric($ns)); // outputs 1, $ns is a numeric string
?>
===Set up an array of different types of values, iterate through the array, output type, value and whether is_numeric() returns true or false===
$tests = array(
1337,
0x539, // 1337 expressed in hexadecimal format
02471, // 1337 expressed in octal format
0b10100111001, // 1337 expressed in binary format
-25,
42.8,
-365.0,
"42.9",
"no numbers",
"123 with numbers",
array(1,2,3),
);
for ($i=0;$i
The above example will output:
The int '1337' is numeric
The int '1337' is numeric
The int '1337' is numeric
The int '1337' is numeric
The int '-25' is numeric
The float '42.799999' is numeric
The float '-365.011138' is numeric
The string '42.9' is numeric
The string 'no numbers' is NOT numeric
The string '123 with numbers' is NOT numeric
The array is NOT numeric
====Notes====
Unlike functions [[is_int()]], [[is_float()]], [[is_string()]] and [[is_array()]] this function looks at more than just the type of the variable, it also checks strings to see if they are numeric.
====See Also====
[[is_int()]] - Check if a variable is an integer
[[is_float()]] - Check if a variable is a float
[[is_string()]] - Check if a variable is a string
[[is_array()]] - Check if a variable is an array
[[isset()]] - Check if a variable exists
[[uphp:numbers|uPHP Numbers and Numeric Calculations]]
[[uphp:variables|uPHP Variable Types and Limits]]
[[array()]] - Create an array, with optional values