store the value to array, and select array intersected

87 views Asked by At

1.I would like to store the array value to this three variable, and take the intersected value of it, but it did not work!

$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

There are 1 answers

8
saulnier On

The result of an array_intersect is an array itself, thus replace the last line of code with something like:

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

In addition:

echo var_dump($report);

doesn't make much sense, use only the latter (var_dump) for arrays... .