Question about integers (php) [duplicate]
Possible Duplicate:
PHP: Shortest way to check if a variable contains positive integer?
How do I know, is a given variable a number without residue (and not a negative number)?
Like we have numbers (each number is a variable): 5; 6.416; -76; 254.
Its better to have some function, which would give true or开发者_如何学Go false, like:
number "5" is true
6.416 is false (has residue "416")
-76 is false
254 is true.
Thanks.
if ( (int)$num == $num && (int)$num > 0 ){
return true;
}
This should do it:
function is_positive_int($n) {
return $n && abs(intval($n)) == $n;
}
精彩评论