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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux