note 112278 added to function.ksort
| From: | daniil dot rakhmatulin at gmail dot com | Date: | Mon, 27 May 2013 05:34:44 +0000 |
| Subject: | note 112278 added to function.ksort | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-194962@lists.php.net to get a copy of this message | ||
lists gruping
list = goupBy(list, ['guping_field' => 'sorting_order', ... ])
function groupBy($list, array $keys)
{
if (!empty($keys))
{
foreach ($keys as $key => $sort)
{
$temp = [];
foreach ($list as $row)
{
if (array_key_exists($key, $row))
{
if (is_object($row))
{
$temp[(string)$row->$key][] = $row;
}
elseif (is_array($row))
{
$temp[(string)$row[$key]][] = $row;
}
}
}
if (strtolower($sort) == 'asc')
{
ksort($temp, SORT_NATURAL);
}
elseif (strtolower($sort) == 'desc')
{
krsort($temp, SORT_NATURAL);
}
$list = [];
foreach ($temp as $group)
{
foreach ($group as $row)
{
$list[] = $row;
}
}
}
}
return $list;
}
----
Server IP: 69.147.83.199
Probable Submitter: 87.247.33.3
----
Manual Page -- http://php.net/manual/en/function.ksort.php
Edit -- https://master.php.net/note/edit/112278
Del: integrated -- https://master.php.net/note/delete/112278/integrated
Del: useless -- https://master.php.net/note/delete/112278/useless
Del: bad code -- https://master.php.net/note/delete/112278/bad+code
Del: spam -- https://master.php.net/note/delete/112278/spam
Del: non-english -- https://master.php.net/note/delete/112278/non-english
Del: in docs -- https://master.php.net/note/delete/112278/in+docs
Del: other reasons-- https://master.php.net/note/delete/112278
Reject -- https://master.php.net/note/reject/112278
Search -- https://master.php.net/manage/user-notes.php