Best way to check for positive integer (PHP)?

前端 未结 20 2306
心在旅途
心在旅途 2020-12-02 18:34

I need to check for a form input value to be a positive integer (not just an integer), and I noticed another snippet using the code below:

$i = $user_input_v         


        
20条回答
  •  难免孤独
    2020-12-02 18:58

    The first example is using round to verify that the input is an integer, and not a different numeric value (ie: a decimal).

    is_int will return false if passed a string. See the PHP manual examples for is_int

提交回复
热议问题