public static function groupArray($arr, $groupField)
    {
        $result = array();
        foreach ($arr as $data) {
            $id = $data[$groupField];
            if (isset($result[$id])) {
                $result[$id][] = $data;
            } else {
                $result[$id] = array($data);
            }
        }

        return $result;
    }
public static function groupArray($arr, $groupField)
    {
        $result = array();
        foreach ($arr as $data) {
            $id = $data[$groupField];
            if (isset($result[$id])) {
                $result[$id][] = $data;
            } else {
                $result[$id] = array($data);
            }
        }

        return $result;
    }
public static function groupArray ( $ arr , $ groupField ) { $ result = array ( ) ; foreach ( $ arr as $ data ) { $ id = $ data [ $ groupField ] ; if ( isset ( $ result [ $ id ] ) ) { $ result [ $ id ] [ ] = $ data ; } else { $ result [ $ id ] = array ( $ data ) ; } } return $ result ; }
Groupping elements by field

Example:
$arr = [
[
'groupId' => 1,
'name' => 'name11'
],
[
'groupId' => 1,
'name' => 'name12'
],
[
'groupId' => 2,
'name' => 'name21'
]
];

$result = ArrayHelper::groupArray($arr, 'groupId');

$result:
[
'1' => [
[
'groupId' => 1,
'name' => 'name11'
],
[
'groupId' => 1,
'name' => 'name12'
]
],
'2' => [
[
'groupId' => 2,
'name' => 'name21'
]
]
]

@param array $arr
@param string $groupField
Groupping elements by field