RE: [PHP] Sorting a multi-dimensional array
| From: | Michael Egan | Date: | Wed, 21 Aug 2002 07:43:10 +0000 |
| Subject: | RE: [PHP] Sorting a multi-dimensional array | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-113413@lists.php.net to get a copy of this message | ||
Ben,
I don't know whether this is the most efficient way of doing things but when I've tried in
the past to sort multidimensional arrays according to a number of values I've ended up giving
up on the PHP functions and creating a temporary table in MySQL.
You can then retrieve the information sorted by various fields defined in your query to the
database.
Others may well advise that this is not the best way of doing this but it's worked for me and
has saved me beating myself up over not being able to get to grips with some complex functions!
Michael Egan
-----Original Message-----
From: Ben [mailto:ben_heuer@artlover.com]
Sent: 20 August 2002 18:25
To: php-general@lists.php.net
Subject: [PHP] Sorting a multi-dimensional array
I have looked at array_multisort, asort, etc. NONE of them do what I need.
My array looks like this:
$array[0][0] = First Id;
$array[0][1] = First Name;
$array[0][2] = First Rating;
$array[1][0] = Second Id;
$array[1][1] = Second Name;
$array[1][2] = Second Rating;
$array[2][0] = Third Id;
$array[2][1] = Third Name;
$array[2][2] = Third Rating;
Now, I want to sort the array (very very fast if possible cuz the array is
huge...150 such values) based on the "Rating" for each candidate, which is
the third column inside this matrix array. How should I ask PHP to do this?
Also, when I do sort by the Rating I want the ID and the name to remain the
same for each candidate, i.e., I want the indexes to be maintained.
HELP!
Thanks in advance
Ben
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php