note 101634 deleted from function.asort by danbrown
| From: | danbrown@php.net | Date: | Fri, 31 Dec 2010 16:03:21 +0000 |
| Subject: | note 101634 deleted from function.asort by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-175376@lists.php.net to get a copy of this message | ||
Note Submitter: swapnil dot nkene at gmail dot com
----
multi-dimensional array sort keeping keys.
function array_sort($array, $sortkey)
{
foreach($array as $key=>$item)
{
$sort_values[$key] = $array[$key][$sortkey];
}
asort ($sort_values);
reset ($sort_values);
while (list ($arr_key, $arr_val) = each ($sort_values)) {
$sorted_arr[$arr_key] = $array[$arr_key];
}
return $sorted_arr;
}
//Call to this like
array_sort($array,$key);