Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2000071

[PHP] Sorting a Two-Dimensional Array From: Waldo L. Jaquith (waldo <email protected>)
Date: 07/14/00

Folks,

I've searched the archives over for this, but I can't find a response that's
really pertinent to what I'm doing. I'm new at multi-dimensional arrays, so
please bear with me. :)

I've got an array like this:

$array[1][id]
$array[1][rating]
$array[2][id]
$array[2][rating]
$array[3][id]
$array[3][rating]

I'd like to sort by rating. So if the data looked like this:

$array[1][501]
$array[1][5]
$array[2][467]
$array[2][1]
$array[3][468]
$array[3][3]

I'd like to sort by rating, for it to end up looking like this:

$array[2][467]
$array[2][1]
$array[3][468]
$array[3][3]
$array[1][501]
$array[1][5]

You'll note that it's now in order of 1, 3, 5, instead of 5, 1, 3. In SQL,
this would be wicked easy. I could just do "ORDER BY rating". With
two-dimensional arrays, of course, it's not so easy. I'm aware that I
should be using usort, but I don't know how to go about applying it. I was
hoping for something like "usort($array,rating,asc)", but Momma always
called me a dreamer. :)

Thanks in advance for any help you can offer, fellow PHPers.

Best,
Waldo

                              Waldo L. Jaquith
                                 < waldo <email protected> >
                                 < 804/979.2980 >
                                       // Munk & Phyber
                                       // 110B Second Street NE
                                       // Charlottesville, VA 22902

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe <email protected>
For additional commands, e-mail: php-general-help <email protected>
To contact the list administrators, e-mail: php-list-admin <email protected>