user2440987
user2440987

Reputation: 19

Getting Unique Values in Multidimensional Array PHP

I have an array similar to this:

array(5) { [0]=> string(2) "32" [1]=> string(2) "67" [2]=> string(19) "2013-07-15 15:56:28" [3]=> string(1) "1" [4]=> string(4) "Fail"}
array(5) { [0]=> string(2) "32" [1]=> string(2) "89" [2]=> string(19) "2013-09-15 13:50:34" [3]=> string(1) "2" [4]=> string(4) "Pass"}
array(5) { [0]=> string(2) "37" [1]=> string(2) "55" [2]=> string(19) "2013-07-15 16:36:12" [3]=> string(1) "1" [4]=> string(4) "Fail"}
array(5) { [0]=> string(2) "39" [1]=> string(2) "92" [2]=> string(19) "2013-08-15 15:46:20" [3]=> string(1) "1" [4]=> string(4) "Pass"}

The first value displays a content ID, the second a score, the third a date, the fourth an attempt number (no limit), and the fifth a result. I want to print these values in the browser, but if there is more than one attempt, I only want to print the one with the highest score. I can't seem to get it working, any help would be greatly appreciated.

Upvotes: 1

Views: 687

Answers (1)

Sumoanand
Sumoanand

Reputation: 8929

The way you can achieve this is:

  • 1st: Group the results by content ID.
  • 2nd: Descending Order the sub-array by score using usort
  • 3rd: Display the 1st sub-array to user for each content ID.

Upvotes: 1

Related Questions