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

New function for grouping elements by unique key

This func have the same behaviour as `as_array` function, but the last one make array of [keys => arrays].

`groupByUniqueKey` just an array of [unique key => array].
parent 77a53b0b
Branches
Tags
No related merge requests found
......@@ -171,6 +171,18 @@ abstract class Kohana_Database_Result implements Countable, Iterator, SeekableIt
return $results;
}
public function groupByUniqueKey($key) {
$results = [];
foreach ($this as $row) {
$results[$row[$key]] = $row;
}
$this->rewind();
return $results;
}
/**
* Return the named column from the current row.
*
......
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