Group an associative array by a field or Closure value.

@param Closure|string $group

@return static
350110
public function groupBy( $group )
    {
        $result = [ ];

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

        return new static( $result );
    }
347758
function addToGroup($group)
    {
        $this->_api->doRequest("PUT", "{$group->getBaseApiPath()}/contacts/{$this->id}");               
        $this->_group_ids_set[$group->id] = true;        
    }
801810
public function setGroups(array $groups)
    {
        $this->groups = [];

        foreach ($groups as $groupIdent => $group) {
            $this->addGroup($groupIdent, $group);
        }

        uasort($this->groups, [ $this, 'sortGroupsByPriority' ]);

        // Remove items that are not active.
        $this->groups = array_filter($this->groups, function($item) {
            return ($item->active());
        });

        return $this;
    }
1220742
public function group(array $rule, Closure $closure)
    {
        $rule = new GroupRule($rule, $closure);
        $rule->setGroup($this);
        $this->children[] = $rule;
        return $rule;
    }
444306
private function addGroup($group)
	{
		if($group != null)
		{
			if($this->_groups == null)
				$this->_groups = array();
			$this->_groups[] = $group;
		}
	}
1192825
public function setGroup($group)
    {
        $this->group = $group instanceof SID ? $group : new SID($group);

        return $this;
    }
1338819
public function inGroup($group = null) {
    if (is_numeric($group)) {
      $group = Group::factory((int) $group);
    }
    if (!isset($group->guid)) {
      return false;
    }
    return ($group->inArray((array) $this->groups) || $group->is($this->group));
  }
760274
public function group(array $options, \Closure $closure)
	{
		$group = new static(null, $options);

		$closure->bindTo($group)->__invoke($group);

		$this->getCollection()->addAll($group->getCollection());

		return $this;

	}
831117
protected function bindLevel($group, $data)
	{
		// Ensure the input data is an array.
		settype($data, 'array');

		// Process the input data.
		foreach ($data as $k => $v)
		{
			if ($this->findField($k, $group))
			{
				// If the field exists set the value.
				$this->data->set($group . '.' . $k, $v);
			}
			elseif (is_object($v) || Arr::isAssociative($v))
			{
				// If the value is an object or an associative array, hand it off to the recursive bind level method
				$this->bindLevel($group . '.' . $k, $v);
			}
		}
	}
1346720
public function setMimeTypeGroup(string $group = null)
    {
        if (null !== $group && !\in_array($group, self::$validGroups, true)) {
            throw new \InvalidArgumentException(\sprintf(
                'Unknown MIME-type group "%s" given. Expected "%s" or null.',
                $group,
                \implode(', ', self::$validGroups)
            ));
        }

        $this->mimeTypeGroup = $group;

        return $this;
    }
416375
public function setActualFields($group = UNDEFINED)
    {
        if (is_array($group)) {
            $this->actual_fields = $group;

            return $this;
        }
        if ($group === UNDEFINED) {
            $group = 'all';
        }
        $this->actual_fields = $this->getGroupField($group);

        return $this;
    }
754502
public function setGroup(array $group)
    {
        try {

            // need to return << true
            $this->validator->verify($group, [
                'isArray', 'isNotEmpty', 'isExists'
            ], 'group');

        }
        catch(ExceptionFactory $e) {
            echo $e->getMessage();
        }

        return $this;
    }
1294948
public function group($grouper, bool $saveKeys = false): self
    {
        // init
        $result = [];

        // Iterate over values, group by property/results from closure.
        foreach ($this->getGenerator() as $key => $value) {
            if (\is_callable($grouper)) {
                $groupKey = $grouper($value, $key);
            } else {
                $groupKey = $this->get($grouper, null, $this->getArray());
            }

            $newValue = $this->get($groupKey, null, $result);

            if ($groupKey instanceof self) {
                $groupKey = $groupKey->getArray();
            }

            if ($newValue instanceof self) {
                $newValue = $newValue->getArray();
            }

            // Add to results.
            if ($groupKey !== null) {
                if ($saveKeys) {
                    $result[$groupKey] = $newValue;
                    $result[$groupKey][$key] = $value;
                } else {
                    $result[$groupKey] = $newValue;
                    $result[$groupKey][] = $value;
                }
            }
        }

        return static::create(
            $result,
            $this->iteratorClass,
            false
        );
    }
243244
protected function loadGlobal(/*# string */ $group)
    {
        if (!isset($GLOBALS[$group])) {
            $this->throwError(
                Message::get(Message::CONFIG_GLOBAL_UNKNOWN, $group),
                Message::CONFIG_GLOBAL_UNKNOWN
            );
        }

        // load super global
        $this->config->addNode($group, $GLOBALS[$group]);

        return $this;
    }
867584
public function groupBy(array $collection, Closure $iterator)
    {
        $groups = [];

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

        sort($groups);

        return $groups;
    }
557050
public function addGroup($group) {
    if (!$group->inArray((array) $this->groups)) {
      $this->groups[] = $group;
      return $this->groups;
    }
    return true;
  }
266017
public function setGroups($groups)
    {
        foreach ($groups as $key => $dtoData) {
            $this->groups[$key] = new GroupDto($dtoData);
        }
    
        return $this;
    }