Re: Multi-Sort -- how to do this?

From: Date: Wed, 17 Jun 2009 21:54:21 +0000
Subject: Re: Multi-Sort -- how to do this?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-294183@lists.php.net to get a copy of this message
...Sticking my neck out playing with the big boys (and girls) now... I assume you've looked at array_multisort() for this, I would think you could have multiple arrays being sorted with it (I've only ever used it for 2-array sorts). The other option would be to pop all those arrays into a single array and use array_multisort()'s ability to sort arrays-within-arrays. Otherwise Ashley's solution is another possibility; using the keys in the sorted $d to dictate where you could place the elements in the other arrays. I'd say you could do a nifty loop system which says sequentially read the indices in $d and then make a new temp array that is $a, $b or $c (depending on which you are sorting) in the sorted order then just name the temp array as the original (again, I'd say array_multisort() is fancier than this crude but elegant system). Finally, why not use quicksort or mergesort for the sorting? Bubblesort is inefficient for large lists...

« previous php.general (#294183) next »