note 80420 deleted from function.rsort by mgf

From: Date: Mon, 23 Jun 2008 11:00:13 +0000
Subject: note 80420 deleted from function.rsort by mgf
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-140732@lists.php.net to get a copy of this message
Note Submitter: manallesweg at gmx dot de ---- I just wrote a little function for sort an array in reverse order WITHOUT pre-ordering the numbers in it.. I hope, someone can use it. ;) <?php function rsort_rec($array) { if ( !is_array($array) ) return $array; # return original input when it's not an array $c = count($array); $c--; $j = -1; for ( $i = $c; $i > -1; $i-- ) { $array_rec[] = $array[$i]; } return $array_rec; } $input = array(167, 20, 100, 205); print_r(rsort($input)); # printout reordered array with rsort() # Output: Array ( [0] => 205 [1] => 167 [2] => 100 [3] => 20 ) print_r(rsort_rec($input)); # printout reordered array with rsort_rec() # Output: Array ( [0] => 205 [1] => 100 [2] => 20 [3] => 167 ) ?>

« previous php.notes (#140732) next »