Skip to content
Snippets Groups Projects
Commit b33b44bf authored by xamgore's avatar xamgore
Browse files

Array utils, groupByUniqueKey

parent 9ef253df
Branches
Tags
No related merge requests found
...@@ -30,7 +30,7 @@ class Kohana_Arr { ...@@ -30,7 +30,7 @@ class Kohana_Arr {
*/ */
public static $delimiter = '.'; public static $delimiter = '.';
public static function groupBy($key, array &$array) { public static function groupBy($key, array $array) {
$results = []; $results = [];
foreach ($array as &$row) { foreach ($array as &$row) {
$elem = is_object($row) ? $row->$key : $row[$key]; $elem = is_object($row) ? $row->$key : $row[$key];
...@@ -39,6 +39,16 @@ class Kohana_Arr { ...@@ -39,6 +39,16 @@ class Kohana_Arr {
return $results; return $results;
} }
public static function groupByUniqueKey($key, array $array) {
$results = [];
foreach ($array as &$row) {
$results[$row[$key]] = $row;
}
return $results;
}
/** /**
* Tests if an array is associative or not. * Tests if an array is associative or not.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment