0

所以我正在查询数据库,它会返回一个 id 数组。

$val = $db->prepare("SELECT x FROM xx WHERE x_id='$xx'");
$val->execute();
$res = $val->fetchAll(PDO::FETCH_COLUMN, 0);

然后,我将用逗号分隔数组,

$x= join('', $res);

并呼应它会返回1,18,32

然后我想检查是否$_GET['id']是这些数字之一

if($_GET['id] contains one of these){ // so here lies the problem, how do I check that it contains 1/18 or 32?
//continue...
}
else{
echo "You have no right to view this.";
}

但是怎么做?

4

1 回答 1

2

使用in_array(val, array).

if(in_array($_GET['id'], $res)) echo "Welcome";
else echo "You have no business here.";

参考: http: //php.net/manual/en/function.in-array.php

于 2013-02-10T16:56:55.393 回答