2011-01-25 4 views
1

가능한 중복 : 주어진 변수는 숫자 잔류 물없이 (그리고 음수)
PHP: Shortest way to check if a variable contains positive integer?질문에 대한 정수 (PHP)

는 어떻게 알 수 있습니까입니까?

숫자가 같음 (각 숫자는 변수 임) : 5; 6.416; -76;

number "5" is true 
6.416 is false (has residue "416") 
-76 is false 
254 is true. 

감사 : 254

그것의 더 나은처럼, 참 또는 거짓 줄 것입니다 몇 가지 기능을 가지고 있습니다.

답변

3

이 그것을 수행해야합니다

function is_positive_int($n) { 
    return $n && abs(intval($n)) == $n; 
} 
3
if ((int)$num == $num && (int)$num > 0){ 
    return true; 
}