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

[email protected] ("Ford, Mike")
Newsgroups php.general
Message-ID <93ED589E60BA254F97435FE6C97F2C6702B925BE@leedsmet-exch1.leedsmet.ac.uk>
On 17 June 2009 22:12, tedd advised:

> Hi gang:
> 
> Here's the problem. Let's say you have a collection of
> arrays, such as:
> 
> $a = array();
> $b = array();
> $c = array();
> $d = array();
> 
> And then you populate the arrays like so:
> 
> while(...)
>     {
>     $a[] = ...
>     $b[] = ...
>     $c[] = ...
>     $d[] = ...
>     }
> 
> Now, let's say you want to sort the $d array, but you also want the
> arrays $a, $b, and $c to be arranged in the same resultant order as
$d.
> 
> For example, please follow this:
> 
> Before sort of $d:
> $a = [apple, banana, grape, orange]
> $b = [100, 2111, 198, 150]
> $c = [red, yellow, purple, orange]
> $d = [100, 300, 11, 50]
> 
> After sort of $d:
> $a = [grape, orange, apple, banana]
> $b = [198, 150, 100, 2111]
> $c = [purple, orange, red, yellow]
> $d = [11, 50, 100, 300]

array_multisort($d, $a, $b, $c) should do what you want,

Cheers!

Mike

 --
Mike Ford,  Electronic Information Developer,
C507, Leeds Metropolitan University, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom
Email: [email protected]
Tel: +44 113 812 4730


To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm
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.