So I'm querying database, and it will return an array of id's.
所以我在查询数据库,它会返回一个id的数组。
$val = $db->prepare("SELECT x FROM xx WHERE x_id='$xx'");
$val->execute();
$res = $val->fetchAll(PDO::FETCH_COLUMN, 0);
Then, I will separate the array with commas,
然后,我将用逗号分隔数组,
$x= join('', $res);
and echoing it would return 1,18,32
.
并回应它将返回1,18,32。
Then I want to check if $_GET['id']
is one of these numbers
然后我想检查$ _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.";
}
But how?
1 个解决方案
#1
2
Use in_array(val, array)
.
使用in_array(val,array)。
if(in_array($_GET['id'], $res)) echo "Welcome";
else echo "You have no business here.";
#1
2
Use in_array(val, array)
.
使用in_array(val,array)。
if(in_array($_GET['id'], $res)) echo "Welcome";
else echo "You have no business here.";