我检索了一个查询,并尝试将id列存储在一个数组中。然后我用array_intersect函数检查两个数组,找出它们的共同点。
<?php
$a=array(10);
$connection = mysql_connect("localhost","root","");
$db=mysql_select_db("data",$connection);
$res=mysql_query("select * from usertable");
$i=0;
while($row=mysql_fetch_array($res))
{
$a[i]=$row["id"];
$i++;
}
echo $a[1];
$fb_usr_id =json_decode( $_POST['fb_user'], true );
$arr=array($fb_usr_id);
$result = array_intersect($arr, $a);
print_r($result);
?>我在数组中存储检索到的值的方式是否正确...??此代码的输出为:
Array ()
发布于 2011-06-14 23:18:41
你做这件事的方式非常好。
您的结果只是意味着两个数组之间没有连接。
我不知道你为什么要$arr=array($fb_usr_id);,你把一个数组放在一个数组里面?
删除这一行应该会得到正确的结果。
现在,您正在将array(array(...))与永远不会相交的array(...)进行比较
发布于 2011-06-14 23:14:48
我会这样做的
<?php
$a;
$connection = mysql_connect("localhost","root","");
$db=mysql_select_db("data",$connection);
$res=mysql_query("select id from usertable");
$i=0;
while($row=mysql_fetch_array($res))
{
$a[]=$row["id"];
}
echo $a[1];
$fb_usr_id =json_decode( $_POST['fb_user'], true );
$arr=array($fb_usr_id);
$result = array_intersect($arr, $a);
print_r($result);
?>https://stackoverflow.com/questions/6345812
复制相似问题