Re: array sort

From: Date: Mon, 21 May 2001 22:57:07 +0000
Subject: Re: array sort
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53790@lists.php.net to get a copy of this message
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

« previous php.general (#53790) next »