note 80420 added to function.rsort
| From: | manallesweg at gmx dot de | Date: | Tue, 15 Jan 2008 10:03:32 +0000 |
| Subject: | note 80420 added to function.rsort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-135111@lists.php.net to get a copy of this message | ||
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 )
?>
----
Server IP: 69.147.83.197
Probable Submitter: 91.63.208.47
----
Manual Page -- http://www.php.net/manual/en/function.rsort.php
Edit -- https://master.php.net/note/edit/80420
Del: integrated -- https://master.php.net/note/delete/80420/integrated
Del: useless -- https://master.php.net/note/delete/80420/useless
Del: bad code -- https://master.php.net/note/delete/80420/bad+code
Del: spam -- https://master.php.net/note/delete/80420/spam
Del: non-english -- https://master.php.net/note/delete/80420/non-english
Del: in docs -- https://master.php.net/note/delete/80420/in+docs
Del: other reasons-- https://master.php.net/note/delete/80420
Reject -- https://master.php.net/note/reject/80420
Search -- https://master.php.net/manage/user-notes.php