public static function groupByKey(array $arrayList, $key = 'id'): array
    {
        $result = [];

        foreach ($arrayList as $item) {
            if (is_object($item)) {
                if (isset($item->{$key})) {
                    $result[$item->{$key}][] = $item;
                }
            } elseif (is_array($item)) {
                if (self::key($key, $item)) {
                    $result[$item[$key]][] = $item;
                }
            }
        }

        return $result;
    }
public static function groupByKey(array $arrayList, $key = 'id'): array
    {
        $result = [];

        foreach ($arrayList as $item) {
            if (is_object($item)) {
                if (isset($item->{$key})) {
                    $result[$item->{$key}][] = $item;
                }
            } elseif (is_array($item)) {
                if (self::key($key, $item)) {
                    $result[$item[$key]][] = $item;
                }
            }
        }

        return $result;
    }
public static function groupByKey ( array $ arrayList , $ key = 'id' ) : array { $ result = [ ] ; foreach ( $ arrayList as $ item ) { if ( is_object ( $ item ) ) { if ( isset ( $ item -> { $ key } ) ) { $ result [ $ item -> { $ key } ] [ ] = $ item ; } } elseif ( is_array ( $ item ) ) { if ( self :: key ( $ key , $ item ) ) { $ result [ $ item [ $ key ] ] [ ] = $ item ; } } } return $ result ; }
Group array by key

@param array  $arrayList
@param string $key
@return array
Group array by key