Check if a variable is a natural number
If you don't require decimal points: ctype_digit
or filter_var($var, FILTER_VALIDATE_INT)
.
If you do: filter_var($var, FILTER_VALIDATE_FLOAT)
.
ctype_digit does what you want:
Checks if all of the characters in the provided string, text, are numerical.
(Before PHP 5.1.0, this function returned TRUE when text was an empty string.)