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 Quote 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 Quote 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']; Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.