dsaba Posted April 24, 2007 Share Posted April 24, 2007 I have 2 arrays: $array1[] = 'hello'; $array1[] = 'how'; $array1[] = 'are'; $array1[] = 'you'; $array1[] = 'bob'; $array2[] = 'hello how'; $array2[] = 'are you steve'; I want to compare $array1 with $array2, and if any value of $array1 is found in $array2 I want to perform an action I know this has to be in a loop, i'm confused about how to set it up Link to comment https://forums.phpfreaks.com/topic/48432-comparing-2-arrays-in-a-loop/ Share on other sites More sharing options...
ToonMariner Posted April 24, 2007 Share Posted April 24, 2007 it dose'nt need a loop. $matches = array_intersect($array1,$array2); if (count($matches) > 0) { // matches found so do you stuff. print_r($matches); // print the matches just to check. } Link to comment https://forums.phpfreaks.com/topic/48432-comparing-2-arrays-in-a-loop/#findComment-236810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.