PHPackages                             efk3/grouping - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. efk3/grouping

ActiveLibrary

efk3/grouping
=============

Grouping library provides a class to create groups with different options. You add members and the class will try to pair those members to groups. It can be very helpful in some cases, like create a tag cloud.

012PHP

Since Jun 14Pushed 12y ago1 watchersCompare

[ Source](https://github.com/Efk3/Grouping)[ Packagist](https://packagist.org/packages/efk3/grouping)[ RSS](/packages/efk3-grouping/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Grouping
========

[](#grouping)

Grouping library provides a class to create groups with different options. You add members and the class will try to pair those members to groups. It can be very helpful in some cases, like create a tag cloud.

Installation
------------

[](#installation)

You can install it with composer:

```
"efk3/grouping": "1.0.*@dev"

```

Options
-------

[](#options)

When you create a group you can choose from these options:

- `id` - Required. ID of the group.
- `min` - The group should contain *value* members at least.
- `max` - The group should contain *value* members at most.
- `member` - Combination of `min` and `max` options.
- `min_percent` - The group should contain *value* percent of the members at least.
- `max_percent` - The group should contain *value* percent of the members at most.
- `percent` - Combination of `min_percent` and `max_percent` options.
- `constraints` - Member has to satisfy the `constraints`. You can choose constraints from [Symfony constraints classes](http://symfony.com/doc/master/reference/constraints.html).

Members don't have any special options unless you set sort to true then all members must have the sort key.

How to use constraint
---------------------

[](#how-to-use-constraint)

```
use Symfony\Component\Validator\Constraints as Assert;

$grouping->addGroup(array(
	"id"			=>	1,
	"constraints"	=>	array(
		"arrayKeyName" => array(
			new Assert\Min(array("limit" => 10)),
			new Assert\Max(array("limit" => 20)),
		),
	),
));
```

Sorting
-------

[](#sorting)

At default groups will be checked in the order as you have added them. But there is a method

```
$grouping->setSort(true);
```

with the groups will be sorted by `ID` key.

Members also will be sorted by `priority` (default) key. You can change the key with:

```
$grouping->setSortKey("keyname");
```

How is it work?
---------------

[](#how-is-it-work)

Each member will be added maximum one group. If the member is not fit constraints of any group or every group is full then the member won't be added to any group. Also if you added less member than the sum of minimum member options of groups then groups with less priority (by adding or ID order) or without minimum option will be removed.

Tag cloud examle
----------------

[](#tag-cloud-examle)

```
$grouping = new \Efk3\Grouping();
$grouping->addGroups(array(
	array("id" => 1, "member" => 1, "percent" => 3),
	array("id" => 2, "member" => 1, "percent" => 7),
	array("id" => 3, "member" => 1, "percent" => 10),
	array("id" => 4, "percent" => 10),
	array("id" => 5),
	array("id" => 6, "percent" => 10),
	array("id" => 7, "percent" => 10),
	array("id" => 8, "percent" => 10),
	array("id" => 9, "percent" => 10),
))
->setSort(true)
->setSortKey("used")
->addMembers($tags);
/*
	$tags is like this:
	array(
		0 => array("name" => "work", "used" => 17),
 		...
	);
*/

foreach ($grouping->grouping() as $tag) {
	echo "" . $tag["name"] . "\r\n";
}
```

In this example every tag will be added in a group, at least 1 or 3% of members in Group #1, at least 1 or 7% of member in Group #2, etc. and remain members will be added to Group #5, which doesn't have any maximum option. Before grouping members will be sorted by `used` desc. Members with highest `used` value will be added to Group #1.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

---

Top Contributors

[![Efk3](https://avatars.githubusercontent.com/u/2657358?v=4)](https://github.com/Efk3 "Efk3 (1 commits)")

### Embed Badge

![Health badge](/badges/efk3-grouping/health.svg)

```
[![Health](https://phpackages.com/badges/efk3-grouping/health.svg)](https://phpackages.com/packages/efk3-grouping)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
