Check for Integer value
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.
delicious | digg