The function is_numeric() verifies whether a variable is a number or a numeric string.
bool is_numeric ( mixed $value )
Sr.No | Parameter & Description |
---|---|
1 |
value The variable value to be evaluated |
This function returns true if value is a number or a numeric string, false otherwise.
PHP 4 and above.
Following example demonstrates return values with different types of variables −
<?php $test_variable = array( "21", 1443, 0x539, 01341, 0b10100111001, 1337e0, "0x539", "01341", "0b10100111001", "1337e0", "tutorialspoint", array(), 9.1, null, '', ); foreach ($test_variable as $var) { if (is_numeric($var)) { echo $var . " is numeric <br>"; } else { echo $var. " is NOT numeric<br>"; } } ?>
This will produce following result −
21 is numeric 1443 is numeric 1337 is numeric 737 is numeric 1337 is numeric 1337 is numeric 0x539 is NOT numeric 01341 is numeric 0b10100111001 is NOT numeric 1337e0 is numeric tutorialspoint is NOT numeric Array is NOT numeric 9.1 is numeric is NOT numeric is NOT numeric