Group an associative array by a field or Closure value.

@param  callable|string  $groupBy
@return \Nova\Support\Collection
189651
public function groupBy($groupBy)
    {
        $results = array();

        foreach ($this->items as $key => $value) {
            $key = is_callable($groupBy) ? $groupBy($value, $key) : data_get($value, $groupBy);

            $results[$key][] = $value;
        }

        return new static($results);
    }
177846
public function addGroupBy($_)
    {
        RecursiveArgs::each(func_get_args(), function ($arg) {
            $this->groupByClauses[] = $arg;
        });

        return $this;
    }
81913
public function groupBy($groupBy)
    {
        if (is_string($groupBy)) {
            if (strpos($groupBy, '(') !== false) {
                if (preg_match('#^([\w\.]+)\((.*)\)$#', $groupBy, $match) === 1) {
                    $func = strtoupper($match[1]);
                    if ($func === 'SUBSTR') {
                        $parts = explode(',', $match[2]);

                        if ($parts[1] === '0') {
                            throw new MisuseException(['`:group` substr index is 1-based', 'group' => $groupBy]);
                        }
                        $this->_group[$parts[0]] = ['$substr' => ['$' . $parts[0], $parts[1] - 1, (int)$parts[2]]];
                    }
                } else {
                    throw new MisuseException(['`:group` group is not supported. ', 'group' => $groupBy]);
                }
            } else {
                foreach (explode(',', str_replace(' ', '', $groupBy)) as $field) {
                    $this->_group[$field] = '$' . $field;
                }
            }
        } elseif (is_array($groupBy)) {
            foreach ($groupBy as $k => $v) {
                if (is_int($k)) {
                    $this->_group[$v] = '$' . $v;
                } else {
                    $this->_group[$k] = $v;
                }
            }
        }

        return $this;
    }
883883
public function formatGroupBy(array $groupBy) {
        if ($groupBy) {
            return sprintf($this->getClause(self::GROUP_BY), $this->quoteList($groupBy));
        }

        return '';
    }
889486
public function groupBy($fields)
    {
        if (!is_array($fields)) {
            $fields = $this->splitParts($fields);
        }

        foreach ($fields as $k => $field) {
            $fields[$k] = $this->db->quoteColumn($field);
        }

        $this->query['group'] = implode(',', $fields);

        return $this;
    }
519575
public function groupBy($field): IQueryBuilderHandler
    {
        if (($field instanceof Raw) === false) {
            $field = $this->addTablePrefix($field);
        }

        if (\is_array($field) === true) {
            $this->statements['groupBys'] = array_merge($this->statements['groupBys'], $field);
        } else {
            $this->statements['groupBys'][] = $field;
        }

        return $this;
    }
1060755
public function groupBy($groupBy, $preserveKeys = false)
    {
        $groupBy = $this->valueRetriever($groupBy);

        $results = [];

        foreach ($this->items as $key => $value) {
            $groupKeys = $groupBy($value, $key);

            if (!is_array($groupKeys)) {
                $groupKeys = [$groupKeys];
            }

            foreach ($groupKeys as $groupKey) {
                $groupKey = is_bool($groupKey) ? (int) $groupKey : $groupKey;

                if (!array_key_exists($groupKey, $results)) {
                    $results[$groupKey] = new static;
                }

                $results[$groupKey]->offsetSet($preserveKeys ? $key : null, $value);
            }
        }

        return new static($results);
    }
522386
public function groupBy($field): QueryBuilderInterface
	{
		if ( ! is_scalar($field))
		{
			$newGroupArray = array_map([$this->driver, 'quoteIdent'], $field);
			$this->state->setGroupArray(
				array_merge($this->state->getGroupArray(), $newGroupArray)
			);
		}
		else
		{
			$this->state->appendGroupArray($this->driver->quoteIdent($field));
		}

		$this->state->setGroupString(' GROUP BY ' . implode(',', $this->state->getGroupArray()));

		return $this;
	}
1342338
public function groupedBy(string ... $groupingColumnNames)
    {
        foreach ($groupingColumnNames as $name) {
            $this->groupingColumns[$name] = $this->table->getColumn($name);
        }

        return $this;
    }
326120
public function index(
        array $filters = [],
        $orderBy = [],
        $groupBy = []
    ) {
        $selection = $this->provider->selectAll($filters, $orderBy, $groupBy);
        $query = $this->provider->query($selection);
        return $query->getResult();
    }
1241054
public function groupBy(...$groups)
    {
        foreach ($groups as $group) {
            $this->groups = array_merge(
                (array) $this->groups,
                array_wrap($group)
            );
        }

        return $this;
    }
98570
public function addGroupBy($groupBy)
    {
        if ($this->groupBy) {
            $this->groupBy .= ', ';
        }

        $this->groupBy .= $groupBy;

        return $this;
    }
158475
public function sortByArrayValues(array $orderBy)
    {
        if (!$orderBy) {
            return $this->target;
        }

        $result = [];

        foreach ($orderBy as $value) {
            if ($keys = array_keys($this->target, $value)) {
                foreach ($keys as $key) {
                    $result[$key] = $value;
                }
            }
        }

        return $result;
    }
1277343
public void setGroupBy(java.util.Collection<GroupDefinition> groupBy) {
        if (groupBy == null) {
            this.groupBy = null;
            return;
        }

        this.groupBy = new java.util.ArrayList<GroupDefinition>(groupBy);
    }
1139127
public function groupBy($fields)
    {
        $fields = is_array($fields) ? $fields : func_get_args();
        $this->groupBy = array_merge($this->groupBy, $fields);
        return $this;
    }
867584
public function groupBy(array $collection, Closure $iterator)
    {
        $groups = [];

        foreach ($collection as $node)
        {
            $groups[$iterator($node)][] = $node;
        }

        sort($groups);

        return $groups;
    }
561834
public function groupBy( $expressions /* expressions ... */ )  {
		$expressions = is_array( $expressions ) ? $expressions : func_get_args();

		$this->modifierBuilder->groupBy( $expressions );
		return $this;
	}