src/Panda/Support/Helpers/ArrayHelper.php
public static function toKeyGroup($collection, $key, $useDotSyntax = false)
    {
        $keyGroupArray = [];
        foreach ($collection as $item) {
            $itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
            $keyValue = self::get($itemArray, $key, null, $useDotSyntax);
            $keyGroupArray[$keyValue][] = $itemArray;
        }

        return $keyGroupArray;
    }
public static function toKeyGroup($collection, $key, $useDotSyntax = false)
    {
        $keyGroupArray = [];
        foreach ($collection as $item) {
            $itemArray = is_array($item) ? $item : (method_exists($item, 'toArray') ? $item->toArray() : []);
            $keyValue = self::get($itemArray, $key, null, $useDotSyntax);
            $keyGroupArray[$keyValue][] = $itemArray;
        }

        return $keyGroupArray;
    }
public static function toKeyGroup ( $ collection , $ key , $ useDotSyntax = false ) { $ keyGroupArray = [ ] ; foreach ( $ collection as $ item ) { $ itemArray = is_array ( $ item ) ? $ item : ( method_exists ( $ item , 'toArray' ) ? $ item -> toArray ( ) : [ ] ) ; $ keyValue = self :: get ( $ itemArray , $ key , null , $ useDotSyntax ) ; $ keyGroupArray [ $ keyValue ] [ ] = $ itemArray ; } return $ keyGroupArray ; }
Group all array items by the given key.

@param array|object[]|mixed $collection
@param string               $key
@param bool                 $useDotSyntax

@return array
Group all array items by the given key .