Link to home
Start Free TrialLog in
Avatar of cbastian-hill
cbastian-hillFlag for United States of America

asked on

PHP remove duplicate values from multidimensional array

I'm trying to figure out how to merge duplicate array entries, in a multidimensional array.

Here's an excerpt of my data:

Accounting/Business - 86.02
   1->Demonstrate analytical and critical-thinking skills with direct application to business environments. => 85.71
   2->Communicate ideas and information effectively both orally and in writing. => 90.48
   3->Demonstrate skill in the use of computer software application and technology in business and industry. => 90.48
   4->Demonstrate skill in the use of computer software application and technology in business and industry. => 85.71

Open in new window


What I'm trying to do is find anywhere that the text is the same, and merge them into a single key=>value pair.  But aside from just merging the text, the numbers need to be added (and averaged) together to create a new number.

Ideally the above snip would become the following snip:

Accounting/Business - 86.02
   1->Demonstrate analytical and critical-thinking skills with direct application to business environments. => 85.71
   2->Communicate ideas and information effectively both orally and in writing. => 90.48
   3->Demonstrate skill in the use of computer software application and technology in business and industry. => 88.095

Open in new window


The new number (88.095) created by the following = ((90.48+85.71)/2).

Anyone have any ideas?  I have been trying to get this all day, but I can't seem to find any info that helps or figure it out myself...  Thanks for any assistance in this...

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

What is the "multi-dimensional" part of this question?  Could you please print the array out with var_dump() and post that in the code snippet?  I think you want to find matching keys and average the values, but I am not sure of the array structure so I can't show you the code yet.

thanks, ~Ray
Afterthought... Please use echo "<pre>"; before the var_dump() - it makes the output much more readable.  And please present a fairly large excerpt (perhaps all the data) so we do not overlook the outliers in the test cases.

Best, ~Ray
ASKER CERTIFIED SOLUTION
Avatar of MarcEasen
MarcEasen
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cbastian-hill

ASKER

Thanks...  I wasn't really thinking...  Following your tip with a slight change, I got it to work...  Thanks!