note 107095 added to function.sort
| From: | graudonas at gmail dot com | Date: | Fri, 06 Jan 2012 15:04:15 +0000 |
| Subject: | note 107095 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185390@lists.php.net to get a copy of this message | ||
Function order_array_num mentioned bellow has one mistake. When array is reassigned, we don't
need to say indexes for a new array such as they were for an old array. It means that instead of
$tmp2[$key] = $array[$key]; we could write just $tmp2[] = $array[$key];. Or the whole function could
look like this:
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[] = $array[$key];
return $tmp2;
}
----
Server IP: 193.219.81.76
Probable Submitter: 78.62.150.123
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- https://master.php.net/note/edit/107095
Del: integrated -- https://master.php.net/note/delete/107095/integrated
Del: useless -- https://master.php.net/note/delete/107095/useless
Del: bad code -- https://master.php.net/note/delete/107095/bad+code
Del: spam -- https://master.php.net/note/delete/107095/spam
Del: non-english -- https://master.php.net/note/delete/107095/non-english
Del: in docs -- https://master.php.net/note/delete/107095/in+docs
Del: other reasons-- https://master.php.net/note/delete/107095
Reject -- https://master.php.net/note/reject/107095
Search -- https://master.php.net/manage/user-notes.php