aeroswat Posted June 28, 2010 Share Posted June 28, 2010 I have 2 arrays 1 has the following values Orange, Banana, Apple The other has the following values Orange, Blue, Green I want to have an array that contains all the values in array 2 that are not in array 1 so it would have Blue, Green Link to comment https://forums.phpfreaks.com/topic/206087-is-there-an-array-function-that-will-do-this/ Share on other sites More sharing options...
premiso Posted June 28, 2010 Share Posted June 28, 2010 I am sure you can use array_uintersect to create your own function for comparing the arrays and removing items that are duplicated. Link to comment https://forums.phpfreaks.com/topic/206087-is-there-an-array-function-that-will-do-this/#findComment-1078325 Share on other sites More sharing options...
ninedoors Posted June 28, 2010 Share Posted June 28, 2010 Not that I know of but you can use a combination of array_intersect and array_diff to get your desired result. $final_array = array_diff($array2, array_intersect($array1, $array2)); Pretty sure that will work. Nick Link to comment https://forums.phpfreaks.com/topic/206087-is-there-an-array-function-that-will-do-this/#findComment-1078327 Share on other sites More sharing options...
aeroswat Posted June 28, 2010 Author Share Posted June 28, 2010 Thanks guys! Link to comment https://forums.phpfreaks.com/topic/206087-is-there-an-array-function-that-will-do-this/#findComment-1078353 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.