Jump to content

Php array intersection: how to combine two loops


LLeoun

Recommended Posts

Hi all,

 

  Here a learner, with the following question:

 

  I need to do:

 

 

   $intersection = array_intersect($array1, $array2);

 

  I obtain $array1:

 

 

 

 

          for( $i = 0; $i < count ($myarray1['data']); $i ++)
          {
               $array1 = $myarray1['data'][$i]['place']['id']; 
               
          } 

       

    And I obtain $array2 from database:

 

 

 

    while($row = mysql_fetch_array( $result )) {

$array2 = $row['name'];

} 

 

 

  But when doing:

 

 

    $intersection = array_intersect($array1, $array2);

 

 

 

    outside of the loops, the variables contain the last record obtained in the loop ..

 

    What do I have to do for $array1 and $array2 to contain all the data looped?

 

    Thanks a ton

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.