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

[email protected] (Paul M Foster)
Newsgroups php.general
Message-ID <[email protected]>
On Wed, Jun 17, 2009 at 10:31:18PM -0400, Robert Cummings wrote:


<snip>

>
> <?php
>
> function tedd_sort( &$arrays )
> {
>     $master = null;
>     $followers = array();
>
>     $first = true;
>     foreach( array_keys( $arrays ) as $key )
>     {
>         if( $first )
>         {
>             $first = false;
>             $master = &$arrays[$key];
>         }
>         else
>         {
>             $followers[] = &$arrays[$key];
>         }
>     }
>
>
>     asort( $master );
>     foreach( array_keys( $master ) as $mkey )
>     {
>         foreach( array_keys( $followers ) as $fkey )
>         {
>             $value = &$followers[$fkey][$mkey];
>             unset( $followers[$fkey][$mkey] );
>             $followers[$fkey][$mkey] = &$value;
>         }
>     }
> }
>
> $a = array( 'apple', 'banana', 'grape', 'orange' );
> $b = array( 100, 2111, 198, 150 );
> $c = array( 'red', 'yellow', 'purple', 'orange' );
> $d = array( 100, 300, 11, 50 );
>
> $arrays = array( &$d, &$a, &$b, &$c );
> tedd_sort( $arrays );
> print_r( $a );
> print_r( $b );
> print_r( $c );
> print_r( $d );
>
> ?>

Wow, tedd has a sort named after him! I'm sooo jealous.

Paul

-- 
Paul M. Foster
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.