PHPackages                             micheledurante/array-aggregate - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. micheledurante/array-aggregate

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

micheledurante/array-aggregate
==============================

A PHP, SQL-like stream aggregate function to group a set of rows by any number of columns. You can also define how to compute groups

v1.1.0(4y ago)011GPL-3.0-or-laterPHPPHP &gt;=7.2

Since Jun 16Pushed 2y ago1 watchersCompare

[ Source](https://github.com/micheledurante/array-aggregate)[ Packagist](https://packagist.org/packages/micheledurante/array-aggregate)[ Docs](https://github.com/micheledurante/array-aggregate)[ RSS](/packages/micheledurante-array-aggregate/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (4)Dependencies (2)Versions (5)Used By (0)

array\_aggregate
================

[](#array_aggregate)

[![Build Status](https://camo.githubusercontent.com/b0f9b84a3a43dcc45acd0b34fdeb8e025559b118b87d9cf07734c8d0318f021e/68747470733a2f2f7472617669732d63692e6f72672f6d696368656c65647572616e74652f61727261792d6167677265676174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/micheledurante/array-aggregate)[![Latest Stable Version](https://camo.githubusercontent.com/5cf2f8953dec895126710d50d6c9a81b750563b91cfca63b2c05eae5c77f195f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d696368656c65647572616e74652f61727261792d6167677265676174652e737667)](https://packagist.org/packages/micheledurante/array-aggregate)[![Latest Stable Version](https://camo.githubusercontent.com/b015d413d4c26a6deb196e06afc5cae0c1d74576bfa6696ccdc6fea36e888d93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696368656c65647572616e74652f61727261792d6167677265676174652e737667)](https://packagist.org/packages/micheledurante/array-aggregate)

A PHP, SQL-like stream aggregate function to group a set of rows by any number of columns. You can also define how to compute groups. Rows are expected to be already sorted on the columns used to aggregate results.

```
function array_aggregate(array $columns, array $rows, callable $compute_func = null): array
```

The order in which columns are given to the function does not affect the output. Columns must comparable with the `===`operator.

Inspired by Craig Freedman's SQL articles on MS dev blog .

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

[](#installation)

As a composer package:

```
composer require micheledurante/array-aggregate

```

Or require the source file in `src/array_aggregate.php`.

Usage
-----

[](#usage)

```
$rows = [
    0 => [
        'store_id' => 1,
        'manager_id' => 2,
        'name' => 'Alice'
    ],
    1 => [
        'store_id' => 2,
        'manager_id' => 3,
        'name' => 'Bob'
    ],
    2 => [
        'store_id' => 2,
        'manager_id' => 3,
        'name' => 'Eve'
    ],
    3 => [
        'store_id' => 2,
        'manager_id' => 4,
        'name' => 'Foobar'
    ]
];

$groups = array_aggregate(array('store_id', 'manager_id'), $rows, function (array $group): array {
    return [
        'store_id' => $group[0]['store_id'],
        'manager_id' => $group[0]['manager_id'],
        'people' => implode(',', array_column($group, 'name'))
    ];
});

var_export($groups);
```

Results in:

```
/*
array (
    0 => array (
        'store_id' => 1,
        'manager_id' => 2,
        'people' => 'Alice'
    ),
    1 => array (
        'store_id' => 2,
        'manager_id' => 3,
        'people' => 'Bob,Eve'
    ),
    2 => array (
        'store_id' => 2,
        'manager_id' => 4,
        'people' => 'Foobar'
    )
)
*/
```

Similar Projects
----------------

[](#similar-projects)

### `array_group_by()`

[](#array_group_by)

By [jakezatecky](https://github.com/jakezatecky/array_group_by). Main difference is that `array_aggregate()` won't change the structure of the array by creating new keys/nested groups. It behaves like the SQL `GROUP BY` clause, which returns the aggregates of the input rows. Both functions can work with multiple keys. `array_aggregate()` doesn't allow a callable to match columns.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

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.

###  Release Activity

Cadence

Every ~234 days

Total

4

Last Release

1822d ago

PHP version history (2 changes)1.0.0PHP &gt;=7.1

v1.1.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/ff7dfd1f88d958170dc8882df71f5543023309b4454d5795c350918a098d614b?d=identicon)[micheledurante](/maintainers/micheledurante)

---

Tags

array-functionphpstream-aggregatephparray-functionsgroup bystream aggregate

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/micheledurante-array-aggregate/health.svg)

```
[![Health](https://phpackages.com/badges/micheledurante-array-aggregate/health.svg)](https://phpackages.com/packages/micheledurante-array-aggregate)
```

###  Alternatives

[imanghafoori/laravel-anypass

A minimal yet powerful package to help you in development.

21421.6k](/packages/imanghafoori-laravel-anypass)

PHPackages © 2026

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