I have a form field that must only contain a numeric value
Is this the best way to evaluate:
if (is_int($myvar) && $myvar > 0)
Or shall I use is_numeric
My number has to do with number of people and can not have decimails or negative numbers.
Then I think that is_int is the best since numbers with decimals is numbers with is_numeric. To make it into a number you can typecase:
$test1 = "8"; // Is a string with the text "8" $test2 = (int)$test1; // test2 becomes an integer
I don't know if you have to transform it to a number, but at least now you know how to do.
Probably the most efficient method would be to use ctype_digit():
if(ctype_digit($value) && $value > 0) { // it's a positive integer } else { // it's something else }