将值存储到数组,并选择相交的数组

时间:2015-06-24 16:56:50

标签: php mysql arrays intersect

1.我想将数组值存储到这三个变量中,并取相交的值,但它不起作用!

$report =array();
$report1 =array();
$report2 =array();
while ($row=mysql_fetch_array($r_query)){
   echo 'Primary first State:' .$row['user_id'].'<br>';
    $report[]=array(
         'id'=>$row['user_id']);
}

while ($rowa=mysql_fetch_array($r_querya)){
   echo 'Primary second State:  ' .$rowa['user_id'].'<br>'; 
 $report1[]=array(
         'id'=>$rowa['user_id']);
}
while ($rowb=mysql_fetch_array($r_queryb)){
   echo 'Primary third State:  ' .$rowb['user_id'].'<br>';  
 $report2[]=array(
         'id'=>$rowb['user_id']);
}
echo var_dump($report);
   $result = array_intersect($report,$report1,$report2);
   echo 'intersect State:  ' .$result;
}
?>

1 个答案:

答案 0 :(得分:0)

array_intersect的结果是一个数组本身,因此用以下代码替换最后一行代码:

echo 'intersect State:  ' . PHP_EOL;
var_dump($result);

另外:

echo var_dump($report);

没有多大意义,只使用后者(var_dump)用于数组......