public function groupBy($criteria)
    {
        $criteria = $this->factoryCallableCriteria($criteria);
        $groups   = $this->create();

        $this->each(function ($element, $key) use ($groups, $criteria) {
            $groupName  = $criteria($element, $key);
            $elements   = $groups->offsetGet($groupName, array());
            $elements[] = $element;
            $groups[$groupName] = $elements;
        });

        return $groups;
    }
public function groupBy($criteria)
    {
        $criteria = $this->factoryCallableCriteria($criteria);
        $groups   = $this->create();

        $this->each(function ($element, $key) use ($groups, $criteria) {
            $groupName  = $criteria($element, $key);
            $elements   = $groups->offsetGet($groupName, array());
            $elements[] = $element;
            $groups[$groupName] = $elements;
        });

        return $groups;
    }
public function groupBy ( $ criteria ) { $ criteria = $ this -> factoryCallableCriteria ( $ criteria ) ; $ groups = $ this -> create ( ) ; $ this -> each ( function ( $ element , $ key ) use ( $ groups , $ criteria ) { $ groupName = $ criteria ( $ element , $ key ) ; $ elements = $ groups -> offsetGet ( $ groupName , array ( ) ) ; $ elements [ ] = $ element ; $ groups [ $ groupName ] = $ elements ; } ) ; return $ groups ; }
Group elements by the given criteria

@param mixed $criteria it can be either a callable function or a string,
representing a key of an element

@return Hash
Group elements by the given criteria