matthewtbaker Posted October 19, 2012 Share Posted October 19, 2012 Hi, Please could you point me in the right direction... I want to compare the two arrays (below) and then remove any duplicate values from my temporary array $arrTemp. In this instance the word 'array' will be removed from $arrTemp as it exists in $arrMain. $arrMain = ('the' , 'main' , 'array'); $arrTemp = ('some' , 'array' , 'stuff'); I have found solutions which merge the two but this doesn't suit what I need. array_unique(array_merge($arrMain, $arrTemp)); If you could please provide a solution that would be great. I'd like to avoid loops if possible. Matt Quote Link to comment https://forums.phpfreaks.com/topic/269667-remove-array-duplicates-without-merging/ Share on other sites More sharing options...
salathe Posted October 19, 2012 Share Posted October 19, 2012 See array_diff. $arrTemp = array_diff($arrTemp, $arrMain) In this case, the array_diff() function returns an array containing all the entries from $arrTemp that are not present in $arrMain. Quote Link to comment https://forums.phpfreaks.com/topic/269667-remove-array-duplicates-without-merging/#findComment-1386267 Share on other sites More sharing options...
jazzman1 Posted October 19, 2012 Share Posted October 19, 2012 Try, $arrMain = array('the' , 'main' , 'array'); $arrTemp = array('some' , 'array' , 'stuff'); $resTemp = array_diff($arrTemp, $arrMain); echo '<pre>'.print_r($resTemp, true).'</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/269667-remove-array-duplicates-without-merging/#findComment-1386270 Share on other sites More sharing options...
matthewtbaker Posted October 22, 2012 Author Share Posted October 22, 2012 Great thanks so much! Quote Link to comment https://forums.phpfreaks.com/topic/269667-remove-array-duplicates-without-merging/#findComment-1386905 Share on other sites More sharing options...
shaddowman Posted October 22, 2012 Share Posted October 22, 2012 (edited) Answer removed since it's already solved... Edited October 22, 2012 by shaddowman Quote Link to comment https://forums.phpfreaks.com/topic/269667-remove-array-duplicates-without-merging/#findComment-1386993 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.