note 104780 added to function.sort
| From: | k4m at osu1 dot php dot net | Date: | Thu, 07 Jul 2011 06:43:43 +0000 |
| Subject: | note 104780 added to function.sort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-181302@lists.php.net to get a copy of this message | ||
little change for nice function from Dollar Hauler Admin. With this change you dont have to add
extra keys just put an array or single string.
example:
$arr = multisort($some_array,
'name',array('id','name','category'));
or
$arr = multisort($some_array, 'name', 'id'); //if you need only name and id
CODE:
function multisort($array, $sort_by, $keys)
{
foreach ($array as $pos => $val) $tmp_array[$pos] = $val[$sort_by];
asort($tmp_array);
foreach ($tmp_array as $pos => $val)
{
$return_array[$pos][$sort_by] = $array[$pos][$sort_by];
if(is_array($keys))
{
foreach($keys as $k) $return_array[$pos][$k] = $array[$pos][$k];
} else $return_array[$pos][$keys] = $array[$pos][$keys];
}
return $return_array;
}
----
Server IP: 69.147.83.197
Probable Submitter: 88.156.207.131
----
Manual Page -- http://www.php.net/manual/en/function.sort.php
Edit -- https://master.php.net/note/edit/104780
Del: integrated -- https://master.php.net/note/delete/104780/integrated
Del: useless -- https://master.php.net/note/delete/104780/useless
Del: bad code -- https://master.php.net/note/delete/104780/bad+code
Del: spam -- https://master.php.net/note/delete/104780/spam
Del: non-english -- https://master.php.net/note/delete/104780/non-english
Del: in docs -- https://master.php.net/note/delete/104780/in+docs
Del: other reasons-- https://master.php.net/note/delete/104780
Reject -- https://master.php.net/note/reject/104780
Search -- https://master.php.net/manage/user-notes.php