How to check whether the type of a variable is integer in PHP

1 Answer

0 votes
$arr = array(100, 3.14, "76", "102.6", 1000000000, null, true, false);
foreach ($arr as $value) 
{
    if (is_int($value))
        echo $value . " - int <br />\n";
    else
        echo $value . " - not int <br />\n";
}


/*
run: 

100 - int 
3.14 - not int 
76 - not int 
102.6 - not int 
1000000000 - int 
- not int 
1 - not int 
- not int  

*/

 



answered Jun 30, 2016 by avibootz

Related questions

2 answers 263 views
8 answers 430 views
4 answers 221 views
2 answers 205 views
3 answers 261 views
3 answers 292 views
1 answer 228 views
...