Re: Multi-Sort -- how to do this?
| From: | Ashley Sheridan | Date: | Wed, 17 Jun 2009 22:08:57 +0000 |
| Subject: | Re: Multi-Sort -- how to do this? | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294184@lists.php.net to get a copy of this message | ||
On Wed, 2009-06-17 at 22:54 +0100, Douglas Temple wrote:
> ...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...
I only mention using a bubblesort as it is the only sorting algorithm i
know!
Thanks
Ash
www.ashleysheridan.co.uk