How to check whether a variable is a number or a numeric string in PHP

3 Answers

0 votes
$n = "123";
   
if (is_numeric($n))   
    echo "yes";
else
    echo "no";

/*
run: 

yes 

*/

 



answered Apr 21, 2016 by avibootz
0 votes
$n = 6354;
   
if (is_numeric($n))   
    echo "yes";
else
    echo "no";

/*
run: 

yes 

*/

 



answered Apr 21, 2016 by avibootz
0 votes
$n = "63ab";
   
if (is_numeric($n))   
    echo "yes";
else
    echo "no";

/*
run: 

no 

*/

 



answered Apr 21, 2016 by avibootz
...