tclogo



HotelsCombined.com

Pages

Archives

Categories


Recent Postings

Recent Comments

Feeds

RSS2 feed

Links

Most Popular Posts

Check for Integer value

Thursday, 13th April 2006 9:26pm
One task that I find myself performing again and again in my PHP programming is checking whether a value or variable is an integer. I have always preferred using regular expressions because of the flexibility they offer (apart from being a fan of them) and so to check if say $var is an integer I would use the following:


if (ereg("^[0-9]+$", $var)) {
return true;
}
else
{
return false;
}


This works fine and well but lately I have found myself using the next routine more and more:


if ($var == strval(intval($var))){
return true;
}
else
{
return false;
}


What I need to find out though is which one of these two is more efficient or which one has more limitations if any.

Post a comment:

 

(required)

(required, but not published)

(optional)





Notify me of follow-up comments via e-mail