PHPackages                             claytron5000/better-arrays - 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. claytron5000/better-arrays

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

claytron5000/better-arrays
==========================

Array wrapper for functional-type array processing.

0.0.1(5y ago)02mitPHPPHP ^7.2CI failing

Since Jul 10Pushed 5y ago1 watchersCompare

[ Source](https://github.com/claytron5000/better-arrays)[ Packagist](https://packagist.org/packages/claytron5000/better-arrays)[ RSS](/packages/claytron5000-better-arrays/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (2)Used By (0)

Better Arrays
=============

[](#better-arrays)

This is a project of spite. It originated when I was tasked with fixing a reporting screen in a web application. The previous developer had done some gnarly repetitive database queries. As the application grew, this page got slower and slower until it started timing out. I knew I could get the data I needed in one query, but I would need to do some significant data reducing and mapping to get it to a state where it would fit into the expected charts and graphs.

Php has an amazing set of array methods; check them out if you haven't: . As someone coming from ES6 JavaScript however, this appears to be a bit overwhelming. In ES6, most array handling can be done with "the big three": `map`, `filter`, `reduce`. Not only that, but you can chain the methods and make beautiful ropey array parsing chains.

```
let arrayOfObjects = array
    .filter(x => x.children.length > 0)
    .reduce((accumulator, x) => {
        let children = x.children.map(child => ({parent: x.name, ...child}))
        return accumulator.concat(children)
    }, [])
    .map(x => new CoolObject(x))

```

In php you might find a method that fits your exact needs, there are 81 methods in that list. However, methods have different signatures, some are editing the array in place, and most importantly, they don't chain.

So in php you might have to do something like this:

```
$filtered = array_filter($array, function($x) { return count($x.children) > 0});
$reduced = array_reduce($filtered, function($x) {
    $children = array_map(function($child) { return ["parent" => $child.name, etc, etc ]}, $x);

}, []);
$mapped = array_map(function($x) { return new CoolObject($x); }, $reduced);

```

You can see I lost interest about halfway through writing that. Also, notice how the method signature of `array_map` flips from `array_reduce` and `array_filter`.

I will admit the php array methods are powerful, but I assert they are overpowered, and as a result, hard to read, hard to write, and generally not user friendly.

I'm eliding one of php major features, keyed arrays. Some methods are included here, but we miss some of the functionality because of the one return policy.

In `Better Arrays` my goal is to make array handling chainable, easy to read, and easy to write. Most important to me are `map`, `filter`, and `reduce`, but there are too many juicy methods, so I included them where it makes sense. Because of the requirement this be chainable, I'm excluding any methods that modify the array in place.

Try it today, have a `BetterArray`.

```
$arrayOfObjects = new BetterArray($array)
    .filter(function($x) { return count($x.children) > 0;})
    .reduce(function($acc, $x) {
        return array_merge($acc, $x.children);
    }, [])
    .map(function($x) { return new CoolObject($x);})
    .returnArray();

```

Usage
-----

[](#usage)

If it's not obvious, this is a very personal project, and I haven't landed on a prefered implementation method yet, so I've inlcuded them all.

```
// Object instantiation
$arr = new BetterArray($array);

// Static method
$arr = BetterArray::funcify($array);

// Function wrapper
$arr = betterArray($array);

```

The BetterArray holding your array returns itself until you use one of the `return` methods. The primary one is `returnArray`, which returns the array in it's last state.

###  Health Score

19

—

LowBetter than 9% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity40

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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2177d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3cae07a7faefb0bd8b2300e5395dc8b5e486c3202e58a9ebf4f930843086b562?d=identicon)[claytron5000](/maintainers/claytron5000)

---

Top Contributors

[![claytron5000](https://avatars.githubusercontent.com/u/5767672?v=4)](https://github.com/claytron5000 "claytron5000 (3 commits)")

### Embed Badge

![Health badge](/badges/claytron5000-better-arrays/health.svg)

```
[![Health](https://phpackages.com/badges/claytron5000-better-arrays/health.svg)](https://phpackages.com/packages/claytron5000-better-arrays)
```

###  Alternatives

[jcc/laravel-vote

The package helps you to add user based vote system to your model

13450.8k1](/packages/jcc-laravel-vote)[barrelstrength/sprout-forms

Simple, beautiful forms. 100% control.

1888.7k4](/packages/barrelstrength-sprout-forms)[ultra-lite/container

2119.3k1](/packages/ultra-lite-container)

PHPackages © 2026

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