Using is_numeric() instead of is_int() for request vars in PHP

So, I finished pulling my hair out trying to debug why is_int wasn’t correctly checking some request vars i was passing via a form.  The php code was checking

if( is_int( $_REQUEST['var'] ) ) { //do something }

And always failed even if the var was an actual integer.  Unfortunately it seems that PHP interprets request variables as strings.  So using the is_numeric() function over comes this by checking of the string value is numeric.  Now, it’s working great!

if( is_numeric( $_REQUEST['var'] ) ) { //do something }

Rate This Article:
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

2 Comments

  1. Russ says:

    Nice!

  2. Silvia says:

    Yes, this is just what I was looking for.

    @Russ

Leave a Comment

You must be logged in to post a comment.