is_numeric-detect if a variable is a numeric or numeric character
<?PHP$tests=Array( "1380", "1e4", "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; }}?>
Program Run Result:
' + ' is numeric' 1380 ' is numeric' 1e4 ' are numeric' not numeric ' are not numeric' Array ' c4>is isn't numeric ' 9.1 ' is numeric
The string 1e4 is also judged to be a number.
The Is_numeric function does not only support 10 binary numbers, but also 16 binary type numbers. So in the use of the verification of pure natural numbers such as QQ number string, to match intval () integer function.
<? PHP $id = 0xff33669f; if (is_numeric($id)) Echo $id, ' Meet the requirements. ‘; // output 4281558687 meets the requirements. Else echo$id, ' does not meet the requirements. ';? >
If you need to determine an integer, you can use the Is_int () function to avoid the occurrence of some strings or legitimate numbers.
Is_numeric can determine whether a variable is a numeric or numeric string, but its scope is too wide. Integers, decimals, exponential representations, and 16 decimal values are judged. It is a bit inappropriate to use it when judging the ID. Today, a new decision function is found: ctype_digit, which can only determine integers, which is better than is_numeric. Other ctype_xdigit determine the 16 binary integer, ctype_alpha determine the letter and so on functions.
PHP determines if the variable is a digital is_numeric ()