PHP is_numeric () function

 

is_numeric ()  function is used to detect whether a variable is numeric or numeric string.

example

<?php
$ var_name1 = 678 ;
$var_name2="a678";
$var_name3="678";
$var_name4="runoob.com";
$ var_name5 = 698.99 ;
$var_name6=array("a1","a2");
$var_name7=+125689.66;
if (is_numeric($var_name1))
{
    echo " $ var_name1 is a digital " PHP_EOL.;
}
else
{
    echo " $ var_name1 not a number " . PHP_EOL;
}
if (is_numeric($var_name2))
{
    echo " $ var_name2 is a digital " PHP_EOL.;
}
else
{
    echo " $ var_name2 not a number " . PHP_EOL;
}
 
$result=is_numeric($var_name3);
echo " [$ var_name3 is digital it?] " $ result.PHP_EOL.;
$result=is_numeric($var_name4);
echo " [$ var_name4 is digital it?] "   $ result.PHP_EOL.;
$result=is_numeric($var_name5);
echo " [$ var_name5 is digital it?] "   $ result.PHP_EOL.;
$result=is_numeric($var_name6);
echo " [$ var_name6 is digital it?] "   $ result.PHP_EOL.;
$result=is_numeric($var_name7);
echo " [$ var_name7 is digital it?] " $ the Result;.
 ?>

Export

678 is the number
a678 not a number 
[ 678 digit?] 1  
[runoob.com is digital it ? ]
[ 698.99 digit?] 1  
[Digital Array is it ? ]
[ 125,689.66 digit?] 1

 

reference:

https://www.runoob.com/php/php-is_numeric-function.html

 

 

Guess you like

Origin www.cnblogs.com/sea-stream/p/11279646.html