2011-01-25 7 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

その良くは次のように、trueまたはfalseを与えるいくつかの機能を、持っています。

答えて

3

これはそれを行う必要があります。

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