PHPackages                             rpkamp/report-array - 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. rpkamp/report-array

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

rpkamp/report-array
===================

Easily create aggregate arrays from flat data

0.2.2(5y ago)211.7k↑37.5%MITPHPPHP ^7.2 || ^8.0CI failing

Since Apr 9Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/rpkamp/report-array)[ Packagist](https://packagist.org/packages/rpkamp/report-array)[ Docs](http://github.com/rpkamp/report-array)[ RSS](/packages/rpkamp-report-array/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (6)Used By (0)

report-array
============

[](#report-array)

Easily create aggregate arrays from flat data.

Creating a structured array from flat data that comes from a relational database for example can be quite a hassle.

Suppose you have data like in the following table:

productcountrycountfooNL5fooUS10barUK3barDE2barDE8And you want to transform it to an array like the following:

```
$report = [
    'foo' => [
        'NL' => 5,
        'US' => 10,
    ],
    'bar' => [
        'UK' => 3,
        'DE' => 10,
    ]
];
```

What you often end up with is code that looks like this:

```
$report = [];
foreach ($rows as $row) {
    if (!isset($report[$row['product']][$row['country']])) {
        $report[$row['product']][$row['country']] = 0;
    }
    $report[$row['product']][$row['country']] += $row['count'];
}
```

The `isset` part takes up 3 lines total and is hard to read. This is where `ReportArray` comes in. Instead of the above you can do the following:

```
$storage = new rpkamp\ReportArray\Storage();
$report = new rpkamp\ReportArray\ReportArray($storage);

foreach ($rows as $row) {
    $report->add($row['product'], $row['country'], $row['count']);
}
```

At any point if you want the array shown above just call `$report->get()`.

That's it. No more isset, just tell the class to add a value and it will assume a value of 0 for any key that was not yet set. If you want a different value than 0 as default value, pass it to the `rpkamp\ReportArray\Storage` class constructor as an argument.

In addition to the `add` method, there is also `sub` for subtraction, `mul` for multiplication, `div` for division, `pow` for powers and `root` for roots.

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

[](#installation)

From the command line run:

```
composer require rpkamp/report-array

```

Adding methods
--------------

[](#adding-methods)

You can easily add your own method if you need to by providing it to `rpkamp\ReportArray\ReportArray#addMethod`.

For example:

```
$storage = new rpkamp\ReportArray\Storage();
$report = new rpkamp\ReportArray\ReportArray($storage);

$report->addMethod('myCustomMethod', function ($carry, $value) {
    return 2 * $carry + $value;
});

$report->set('foo', 2);
$report->myCustomMethod('foo', 10);
$report->get(); // returns ['foo' => 14] (2 * 2 + 10)
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance49

Moderate activity, may be stable

Popularity26

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 98.1% 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.

###  Release Activity

Cadence

Every ~600 days

Total

4

Last Release

1935d ago

PHP version history (4 changes)0.1PHP &gt;=5.4.0

0.2PHP ^7.1

0.2.1PHP ^7.2

0.2.2PHP ^7.2 || ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/79a3929a9bceef3d45d7e4987b268ee6f1a15220959b0724ec66d2a46e0009e3?d=identicon)[rpkamp](/maintainers/rpkamp)

---

Top Contributors

[![rpkamp](https://avatars.githubusercontent.com/u/1059790?v=4)](https://github.com/rpkamp "rpkamp (53 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

arrayreportingaggregate

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/rpkamp-report-array/health.svg)

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

###  Alternatives

[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k430.2M1.4k](/packages/doctrine-collections)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k317.3M3.2k](/packages/symfony-property-access)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k430.4M1.7k](/packages/nette-utils)[league/config

Define configuration arrays with strict schemas and access values with dot notation

565335.0M36](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k13.2M174](/packages/cuyz-valinor)[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.3k459.4k15](/packages/aimeos-map)

PHPackages © 2026

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