Jump to content

deals with simple arrays


phporcaffeine

Recommended Posts


$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:00
15:04
18:30

the element that has the MOST duplicates is;

15:04

I basically need a way to do that.

Any Ideas?

TIA



Who would have thunk it?

" array_count_values(); " , lol

Thanks anyhow folks
Link to comment
https://forums.phpfreaks.com/topic/10862-deals-with-simple-arrays/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.