note 94663 added to function.sort
| From: | Anonymous at osu1 dot php dot net | Date: | Tue, 17 Nov 2009 14:10:36 +0000 |
| Subject: | note 94663 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-162977@lists.php.net to get a copy of this message | ||
toenie's code is wrong, but the fix is easy.
I also added the ability to sort in ascending and descending order.
$order = "ASC" will sort the array in ascending order
$order = "DESC" will sort the array in descending order
Here is the code:
function order_array_num ($array, $key, $order = "ASC")
{
$tmp = array();
foreach($array as $akey => $array2)
{
$tmp[$akey] = $array2[$key];
}
if($order == "DESC")
{arsort($tmp , SORT_NUMERIC );}
else
{asort($tmp , SORT_NUMERIC );}
$tmp2 = array();
foreach($tmp as $key => $value)
{
$tmp2[$key] = $array[$key];
}
return $tmp2;
}
----
Server IP: 80.64.47.13
Probable Submitter: 213.4.112.58
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- https://master.php.net/note/edit/94663
Del: integrated -- https://master.php.net/note/delete/94663/integrated
Del: useless -- https://master.php.net/note/delete/94663/useless
Del: bad code -- https://master.php.net/note/delete/94663/bad+code
Del: spam -- https://master.php.net/note/delete/94663/spam
Del: non-english -- https://master.php.net/note/delete/94663/non-english
Del: in docs -- https://master.php.net/note/delete/94663/in+docs
Del: other reasons-- https://master.php.net/note/delete/94663
Reject -- https://master.php.net/note/reject/94663
Search -- https://master.php.net/manage/user-notes.php