is_int and GET or POST

后端 未结 10 1277
傲寒
傲寒 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 11:17

    The dirty solution I'm using is this:

    $val = trim($_GET['id']);
    $cnd = ($val == (int)$val);
    echo $cnd ? "It's an int" : "Not an int";
    

    Apart from the obvious (ugly code that hides its workings behind specifics of the php engine), does anybody know cases where this goes wrong?

提交回复
热议问题