Re: [PHP] Multi-Sort -- how to do this?

[email protected] (Ashley Sheridan)
Newsgroups php.general
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.