On Mon, May 21, 2001 at 03:19:28PM -0700, Alex Black wrote : 
> hi all,
> 
> I'm trying to do an array sort that takes:
> 
>     $test = array(
>         array( // this is $test[0].
>             string => "this is the second",
>             num => 2
>         ),
>         array( // this is $test[1].
>             string=> "this is the first",
>             num => 1
>         ),
>     );        
> 
> and sorts that array based on $test[$x][num], so I get:
> 
>     $test = array(
>         array( // this was $test[1], now $test[0].
>             string=> "this is the first",
>             num => 1
>         ),
>         array( // this was $test[0], now $test[1].
>             string=> "this is the second",
>             num => 2
>         ),
> 
>     );        

Use 'uasort()':

function my_hash_sort( $a, $b) {
        $a = $a['num'];
        $b = $b['num'];
        if( $a == $b) return 0;
        return ( $a > $b) ? -1 : 1;
}

uasort( $test, 'my_hash_sort');

- Markus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to