Jump to content

Ranking multi-dimensional array


SCook

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.