is_int and GET or POST

后端 未结 10 1291
傲寒
傲寒 2020-12-14 10:44

Why does is_int always return false in the following situation?

echo $_GET[\'id\']; //3
if(is_int($_GET[\'id\']))
    echo \'int\'; //not execut         


        
10条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 10:56

    Because HTTP variables are always either strings, or arrays. And the elements of arrays are always strings or arrays.

    You want the is_numeric function, which will return true for "4". Either that, or cast the variable to an int $foo = (int) $_GET['id']...

提交回复
热议问题