phporcaffeine Posted May 31, 2006 Share Posted May 31, 2006 $array = array("12:00", "13:20", "12:00", "15:04", "18:30", "15:04", "19:19", "15:04", "18:30");1.) The first thing I need to do is identify which elements have duplicate values.2>.) The second thing I need to do is to determin which of the elements that have dupes, has the "most" duplicates.so in the above the elements with duplicates are;12:0015:0418:30the element that has the MOST duplicates is;15:04I basically need a way to do that.Any Ideas?TIAWho would have thunk it?" array_count_values(); " , lolThanks anyhow folks Link to comment https://forums.phpfreaks.com/topic/10862-deals-with-simple-arrays/ Share on other sites More sharing options...
Barand Posted May 31, 2006 Share Posted May 31, 2006 That's the one[code]$k = array_count_values($array);[/code]then[code] // sort in descending orderarsort ($k); // get top itemlist ($val, $count) = each($k);echo "$val occurs $count times";[/code] Link to comment https://forums.phpfreaks.com/topic/10862-deals-with-simple-arrays/#findComment-40699 Share on other sites More sharing options...
mushroom Posted June 1, 2006 Share Posted June 1, 2006 You can use some advanced array functions$new_array= array_unique($old_array); # get rid of dups$new_array2= array_diff_assoc($old_array,$new_array); # get only the dups$keys_old_array= array_keys($new_array2); # keys of dups in old_array other than the first appeance. Link to comment https://forums.phpfreaks.com/topic/10862-deals-with-simple-arrays/#findComment-40976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.