src/Util/ArrayUtils.php
public static function groupElementsByValueKeys($array, $groupKeys) {

        if (!is_array($groupKeys)) {
            $groupKeys = array($groupKeys);
        }

        $newArray = new AssociativeArray();
        foreach ($array as $element) {

            $applyObject = $newArray;
            foreach ($groupKeys as $index => $groupKey) {
                if ($index < sizeof($groupKeys) - 1) {
                    $subArray = $applyObject[$element[$groupKeys[$index]]];
                    if (!$subArray) {
                        $subArray = new AssociativeArray();
                        $applyObject[$element[$groupKeys[$index]]] = $subArray;
                    }
                    $applyObject = $subArray;
                } else {
                    if (!is_array($applyObject[$element[$groupKeys[$index]]])) {
                        $applyObject[$element[$groupKeys[$index]]] = array();
                    }
                    $applyObject[$element[$groupKeys[$index]]][] = $element;

                }
            }

        }

        
        return $newArray->toArray();
    }
public static function groupElementsByValueKeys($array, $groupKeys) {

        if (!is_array($groupKeys)) {
            $groupKeys = array($groupKeys);
        }

        $newArray = new AssociativeArray();
        foreach ($array as $element) {

            $applyObject = $newArray;
            foreach ($groupKeys as $index => $groupKey) {
                if ($index < sizeof($groupKeys) - 1) {
                    $subArray = $applyObject[$element[$groupKeys[$index]]];
                    if (!$subArray) {
                        $subArray = new AssociativeArray();
                        $applyObject[$element[$groupKeys[$index]]] = $subArray;
                    }
                    $applyObject = $subArray;
                } else {
                    if (!is_array($applyObject[$element[$groupKeys[$index]]])) {
                        $applyObject[$element[$groupKeys[$index]]] = array();
                    }
                    $applyObject[$element[$groupKeys[$index]]][] = $element;

                }
            }

        }

        
        return $newArray->toArray();
    }
public static function groupElementsByValueKeys ( $ array , $ groupKeys ) { if ( ! is_array ( $ groupKeys ) ) { $ groupKeys = array ( $ groupKeys ) ; } $ newArray = new AssociativeArray ( ) ; foreach ( $ array as $ element ) { $ applyObject = $ newArray ; foreach ( $ groupKeys as $ index => $ groupKey ) { if ( $ index < sizeof ( $ groupKeys ) - 1 ) { $ subArray = $ applyObject [ $ element [ $ groupKeys [ $ index ] ] ] ; if ( ! $ subArray ) { $ subArray = new AssociativeArray ( ) ; $ applyObject [ $ element [ $ groupKeys [ $ index ] ] ] = $ subArray ; } $ applyObject = $ subArray ; } else { if ( ! is_array ( $ applyObject [ $ element [ $ groupKeys [ $ index ] ] ] ) ) { $ applyObject [ $ element [ $ groupKeys [ $ index ] ] ] = array ( ) ; } $ applyObject [ $ element [ $ groupKeys [ $ index ] ] ] [ ] = $ element ; } } } return $ newArray -> toArray ( ) ; }
Group an array of elements by one or more of it's keys.  Essentially convert into an indexed array for each key type.

@param $array
@param $groupKeys
Group an array of elements by one or more of it s keys . Essentially convert into an indexed array for each key type .