public static function groupBy($list, $iterator, $context = null)
    {
        static::associate($iterator, $context);

        $result = [];
        static::each($list, function ($item) use ($iterator, & $result) {
            static::isScalar($iterator)
                ? $result[static::get($item, $iterator)][] = $item
                : $result[$iterator($item)][] = $item;
        });

        return $result;
    }
public static function groupBy($list, $iterator, $context = null)
    {
        static::associate($iterator, $context);

        $result = [];
        static::each($list, function ($item) use ($iterator, & $result) {
            static::isScalar($iterator)
                ? $result[static::get($item, $iterator)][] = $item
                : $result[$iterator($item)][] = $item;
        });

        return $result;
    }
public static function groupBy ( $ list , $ iterator , $ context = null ) { static :: associate ( $ iterator , $ context ) ; $ result = [ ] ; static :: each ( $ list , function ( $ item ) use ( $ iterator , & $ result ) { static :: isScalar ( $ iterator ) ? $ result [ static :: get ( $ item , $ iterator ) ] [ ] = $ item : $ result [ $ iterator ( $ item ) ] [ ] = $ item ; } ) ; return $ result ; }
Splits a collection into sets, grouped by the result of running each value through iterator. If iterator is a
string instead of a function, groups by the property named by iterator on each of the values.

@category Collection Functions

@param traversable $list the list of items to group
@param callable,scalar $iterator the function to generate the key or a property name
@param object $context optional, if provided will become the context of $iterator

@return array
Splits a collection into sets grouped by the result of running each value through iterator . If iterator is a string instead of a function groups by the property named by iterator on each of the values .