LLeoun Posted February 22, 2011 Share Posted February 22, 2011 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 Link to comment https://forums.phpfreaks.com/topic/228476-php-array-intersection-how-to-combine-two-loops/ Share on other sites More sharing options...
sasa Posted February 22, 2011 Share Posted February 22, 2011 change to while($row = mysql_fetch_array( $result )) { $array2[] = $row['name']; } are you shure that want to compare id in first array with name from database Link to comment https://forums.phpfreaks.com/topic/228476-php-array-intersection-how-to-combine-two-loops/#findComment-1178126 Share on other sites More sharing options...
AbraCadaver Posted February 22, 2011 Share Posted February 22, 2011 And also in the for loop: $array1[] = $myarray1['data'][$i]['place']['id']; Link to comment https://forums.phpfreaks.com/topic/228476-php-array-intersection-how-to-combine-two-loops/#findComment-1178199 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.