Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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.
share|improve this answer
 
Thanks I will give it a shot. –  user2440987 Jul 17 '13 at 17:03
 
you are welcome :) –  Sumoanand Jul 17 '13 at 17:52
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.