Shortest way to check if a variable contains positive integer using PHP?

后端 未结 6 1765
野性不改
野性不改 2020-12-08 11:04

I want to check if user input a positive integer number.

1    = true
+10  = true
.1   = false
-1   = false
10.5 = false


Just a positive number. 
No charact         


        
6条回答
  •  余生分开走
    2020-12-08 11:39

    I would say this is the best way

    if (is_int($num) && $num > 0)
    

    as typecasting to an int is very slow.

提交回复
热议问题