可能重复:
PHP: Shortest way to check if a variable contains positive integer?
我怎么知道,给定的变量是一个没有余数的数字(而不是一个负数)?
就像我们有数字一样(每个数字是一个变量):5;6.416;-76;254。
最好有一些功能,它可以给出真或假,例如:
number "5" is true
6.416 is false (has residue "416")
-76 is false
254 is true.谢谢。
发布于 2011-01-25 08:40:46
这应该可以做到:
function is_positive_int($n) {
return $n && abs(intval($n)) == $n;
}发布于 2011-01-25 08:40:51
if ( (int)$num == $num && (int)$num > 0 ){
return true;
}https://stackoverflow.com/questions/4791365
复制相似问题