SCook Posted October 29, 2008 Share Posted October 29, 2008 Hi all, Here is my problem: I have a list of people who've taken a quiz, they have the number right, and their time. I want to sort them all so that they're organized. I was thinking of an array like: my_array[0][0] = id; my_array[0][1] = number_right; my_array[0][1] = time; Is there a way to sort the array by a specific key? Seems like I should know this, but I'm blocked. Any help would be great, thanks Quote Link to comment https://forums.phpfreaks.com/topic/130638-ranking-multi-dimensional-array/ Share on other sites More sharing options...
.josh Posted October 29, 2008 Share Posted October 29, 2008 sort array_multisort Quote Link to comment https://forums.phpfreaks.com/topic/130638-ranking-multi-dimensional-array/#findComment-677838 Share on other sites More sharing options...
akitchin Posted October 29, 2008 Share Posted October 29, 2008 just to elaborate, in case you're wondering how exactly to use array_multisort(), you'll need to extract the number_right: <?php $number_right = array(); foreach($my_array AS $key => $this_array) { $number_right[$key] = $this_array[1]; } array_multisort($number_right, SORT_DESC, $my_array); echo '<pre>'; print_r($my_array); ?> that's an adaptation of the example in the manual. Quote Link to comment https://forums.phpfreaks.com/topic/130638-ranking-multi-dimensional-array/#findComment-677846 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.