Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP: Is_numeric returns false on 0 [closed]

Is_numeric() as well as is_int() returns false if the value is 0. What can i do instead to verify that a specific value is numbers only in PHP?

Are we heading straight for the Regular Expressions camp, or are there some nice, handy feature for this out there already?

Thanks!

like image 894
Industrial Avatar asked May 05 '10 15:05

Industrial


2 Answers

It is returning true for me in both cases:

var_dump(is_numeric(0));
var_dump(is_int(0));

Result:

bool(true)
bool(true)
like image 52
Sarfraz Avatar answered Oct 01 '22 15:10

Sarfraz


Zero, as an integer is empty. So ensure that there is no check for empty before you check for Is_numeric() or is_int()

like image 27
Webdimension Avatar answered Oct 01 '22 15:10

Webdimension