src/Primitive/Container/Container.php
public function groupBy($groupBy)
    {
        if ($this->isStringable($groupBy, true)) $groupBy = $this->getStringable($groupBy);

        $results = [];

        foreach ($this->items as $key => $value)
        {
            $results[$this->getGroupByKey($groupBy, $key, $value)][] = $value;
        }

        return new static($results);
    }
public function groupBy($groupBy)
    {
        if ($this->isStringable($groupBy, true)) $groupBy = $this->getStringable($groupBy);

        $results = [];

        foreach ($this->items as $key => $value)
        {
            $results[$this->getGroupByKey($groupBy, $key, $value)][] = $value;
        }

        return new static($results);
    }
Group an associative array by a field or callback value.

@param  \Closure|string|StringContract  $groupBy
@return static