aebstract Posted October 9, 2008 Share Posted October 9, 2008 I know that 'array_unique' will give me an array taking out duplicates, is there any way I can create an array and ONLY display duplicates? Let's say I have an array with like 6000 items and 10 items are duplicates, I need to display just the 10 items. Link to comment https://forums.phpfreaks.com/topic/127691-solved-grabbing-duplicates-in-an-array-similar-to-array_unique/ Share on other sites More sharing options...
GingerRobot Posted October 9, 2008 Share Posted October 9, 2008 Something like this: <?php $array = array(1,2,3,3,4,5,5); $unique = array_unique($array); $duplicates = array_diff_assoc($array,$unique); print_r($duplicates); ?> Link to comment https://forums.phpfreaks.com/topic/127691-solved-grabbing-duplicates-in-an-array-similar-to-array_unique/#findComment-660827 Share on other sites More sharing options...
thebadbad Posted October 9, 2008 Share Posted October 9, 2008 And if the duplicates appear more than twice in the array, just run another array_unique() on $duplicates. Edit: How obvious is that.. LOL Link to comment https://forums.phpfreaks.com/topic/127691-solved-grabbing-duplicates-in-an-array-similar-to-array_unique/#findComment-660834 Share on other sites More sharing options...
aebstract Posted October 9, 2008 Author Share Posted October 9, 2008 For what I am doing it won't matter if they are there more than twice or not, just need to know which ones do have dupes. Thanks Link to comment https://forums.phpfreaks.com/topic/127691-solved-grabbing-duplicates-in-an-array-similar-to-array_unique/#findComment-660857 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.