ckeck out asort and arsort

Daryl

-----Original Message-----
From: David Otton [mailto:[EMAIL PROTECTED]
Sent: Friday, June 27, 2003 7:41 PM
To: Sparky Kopetzky
Cc: PHP General
Subject: Re: [PHP] Sorting problem


On Fri, 27 Jun 2003 17:06:50 -0600, you wrote:

>I need to sort an array and have the key 'follow' the value. I know I could
>splice a string, sort it, then split it again but what a pain. Is there a
>simpler way?

AFAIK, there's no one-liner answer here. the usort() family of functions
pass either the key or the value, but never both.

I think you'll have to write this up yourself... depending on your data, you
may find that ksort() will get it 95% in-place, and a quick custom bubble
sort will get you the rest of the way. Or you could just code up your own
quicksort.

Alternatively, if you tweaked your data so it was a numerically-ordered
array of arrays, eg

array(array('key','value'),array('key','value'),array('key','value'))

instead of

array('key'=>'value','key'=>'value','key'=>'value')

then usort() would become a useful solution.

BTW, what's the data source? If it's coming from a SQL query, you can sort
the data on the way in and solve the problem that way.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to