Sunday 4 April 2010

How to Check if the number is numeric in PHP.

When you are working with functions in PHP and sending numeric data you always might want to check if the number passed is an integer.

We do that by using an built-in function and that is is_numeric($MyNum) here $MyNum is a variable that is passed to this function and we can always have if-else condition i.e it will return true if numeric or false if not numeric or vice-versa.

If you take a look at the php documentation, there are plenty of functions that you can look into.

I just thought of sharing this one with you. coz this one is very simple and it can save a lot of time trying to figure out what went wrong if the user has sent data in an incorrect format.

Cheers!

And don't forget to leave comments down below

No comments :