A very basic question it is but I wanted expert advice that is why posting it here.
Here are two functions,
what is the difference between the two ? Are both of them equivalently efficient and includes best practices or Which one of them is better to use in programming.
function is_numeric($number)
{
if(!preg_match("/^[0-9]+$/",$number))
return false;
return true;
}
function is_numeric($number)
{
if(preg_match("/^[0-9]+$/",$number))
return true;
else
return false;
}
Some coding standards state that the first branch should be the one that is more likely, while the else branch should cope with the more exceptional things.
But this is totally esoteric, choose whatever you want.
In my personal opinion, rather use
function is_numeric($number)
{
return preg_match("/^[0-9]+$/",$number);
}
as preg_match returns a boolean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With