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

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

gears/arrays
============

A collection of array conversions and manipulators.

v0.7.0(11y ago)54.5k3MITPHP

Since Sep 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/phpgearbox/arrays)[ Packagist](https://packagist.org/packages/gears/arrays)[ Docs](https://github.com/phpgearbox/arrays)[ RSS](/packages/gears-arrays/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (9)Versions (11)Used By (3)

> Looking for maintainers, I no longer do much if any PHP dev, I have moved on, mostly work in dotnet core, node.js &amp; golang these days. If anyone is keen to take over these projects, get in touch -

The Array Gear
==============

[](#the-array-gear)

[![Build Status](https://camo.githubusercontent.com/f1fdaa846e145939c2d60bc6ad3be7e4a1113610de415e6da6389026174eb1f8/68747470733a2f2f7472617669732d63692e6f72672f70687067656172626f782f6172726179732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpgearbox/arrays)[![Latest Stable Version](https://camo.githubusercontent.com/4980cccffe8c9cbbbe188fb7a1eed49903a330b8a04a7fd39093bb331a5c9f31/68747470733a2f2f706f7365722e707567782e6f72672f67656172732f6172726179732f762f737461626c652e737667)](https://packagist.org/packages/gears/arrays)[![Total Downloads](https://camo.githubusercontent.com/592cf92c5789fbf599fabd75c50d505c9a5b8c2cc2404d051e990205ac58b87b/68747470733a2f2f706f7365722e707567782e6f72672f67656172732f6172726179732f646f776e6c6f6164732e737667)](https://packagist.org/packages/gears/arrays)[![License](https://camo.githubusercontent.com/4cf9d268532074fe6bdfbd867e5883ba441436ecd44eb3629c0e5f1b900a25bb/68747470733a2f2f706f7365722e707567782e6f72672f67656172732f6172726179732f6c6963656e73652e737667)](https://packagist.org/packages/gears/arrays)

A collection of array conversions and manipulators. There are 2 APIs:

- One procedural based using name spaced functions / static method calls.
- And a more fluent object based API.

I am not going to bother documenting every single last function here but please see below for some general usage examples. The rest you can work out for yourself by reading the source, it's fairly straight forward and well commented.

How to Install
--------------

[](#how-to-install)

Installation via composer is easy:

```
composer require gears/arrays:*

```

How to Use
----------

[](#how-to-use)

Here are a few procedural examples:

```
$data = [];

$data = Gears\Arrays\add($data, 'a.b.c', 'd');

// $data now looks like: ['a' => ['b' => ['c' => 'd']]];

Gears\Arrays\set($data, 'a.b.c', 'foo');

// $data now looks like: ['a' => ['b' => ['c' => 'foo']]];

Gears\Arrays\forget($data, 'a.b.c');

// $data now looks like: ['a' => ['b' => []]];
```

In PHP 5.6 you can import functions so you could change the above to:

```
// Import the functions
use function Gears\Arrays\add;
use function Gears\Arrays\set;
use function Gears\Arrays\forget;

// This results in the same array
$data = [];
$data = add($data, 'a.b.c', 'd');
set($data, 'a.b.c', 'foo');
forget($data, 'a.b.c');
```

> NOTE: All function names are camelCased.

Prior to PHP 5.6 this is not possible. So you can do this instead:

```
// Import the Array class
use Gears\Arrays as Arr;

// This results in the same array
$data = [];
$data = Arr::add($data, 'a.b.c', 'd');
Arr::set($data, 'a.b.c', 'foo');
Arr::forget($data, 'a.b.c');
```

> NOTE: Just like the standard array\_ functions included in PHP. Some functions act on a refrence of an array while others will take a copy and return the modifications or other values.

The Fluent Array Object:
------------------------

[](#the-fluent-array-object)

Okay so this is such a massive part of the package it requires it's own HOW-TO section. To get started you can create a new object like so:

```
$data = new Gears\Arrays\Fluent();
$data[] = 'foo';
$data[] = 'bar';

foreach ($data as $item)
{
	echo $item.',';
}

// you would see: foo,bar
```

As you can see the data variable is now an Array-Like object. This is key because some times certian functions will expect real arrays. To get a real array back out of the fluent object you can do this:

```
$real_array = $data->toArray();
```

You may wish to use a factory method to initiate a new Fluent object.

```
// Import the Array class
use Gears\Arrays as Arr;

// Use the factory method
$data = Arr::a();
```

When you are using the Fluent API, please note how the subsequent method call signature changes vs that of the procedural api. You no longer need to provide the array to be performed on as the first argument. This is automatically done for you.

Here is the same example from the procedural api:

```
$data = Arr::a();
$data->add('a.b.c', 'd');
$data->set('a.b.c', 'foo');
$data->forget('a.b.c');
```

Now a keen eye might have thought that on line 2 there is an error. You might be thinking that the second line should look like this:

```
$data = $data->add('a.b.c', 'd');
```

But you would be wrong. Unlike the `Gears\String` package. The Fluent API and the Procedural API of `Gears\Arrays`, while similar, they are not identical. In part this is due to the more complex nature of arrays. Please beware that there are methods in both APIs that have the same name yet do slightly different things.

For example I can also use the add method like so:

```
Arr::a([1,2,3])->add(4)->each(function($v){ echo $v.','; });

// would output: 1,2,3,4,
```

**Recursive Nature:** Unlike a standard `Illuminate\Support\Collection`object a `Gears\Arrays\Fluent` object is recursive. Each new fluent object is only loaded when it is accessed, thus minimizing any performance losses.

Lets show with an example:

```
$data = Arr::a(['a' => ['b' => ['c' => 'd']]]);

print_r($data);

// you would see something like:
Gears\Arrays\Fluent Object
(
	[items:protected] => Array
	(
		[a] => Array
		(
			[b] => Array
			(
				[c] => 'd'
			)
		)
	)
)

// now lets access something
$data['a']['b']['c'];

print_r($data);

// you would now see something like:
Gears\Arrays\Fluent Object
(
	[items:protected] => Array
	(
		[a] => Gears\Arrays\Fluent Object
		(
			[items:protected] => Array
			(
				[b] => Gears\Arrays\Fluent Object
				(
					[items:protected] => Array
					(
						[c] => d
					)
				)
			)
		)
	)
)
```

**Object Access:** The last thing I would like to show off is the way you can now use your array is if it were an object. Again I like my examples:

```
$data1 = Arr::a();
$data1['a'] = [];
$data1['a']['b'] = [];
$data1['a']['b']['c'] = 'd';

$data2 = Arr::a();
$data2->a = [];
$data2->a->b = [];
$data2->a->b->c = 'd';

// $data1 == $data2
```

This Readme only skims the surface of what is possible with the Fluent API. I promise a full set of documentation is coming... but I do have a life as well.

Laravel Integration
-------------------

[](#laravel-integration)

*Gears\\Arrays* has been designed as functionally compatible to the *Laravel Arr*class, in fact it extends the class. Thus everything you could do before you can still do and then some.

By default Laravel does not alias the Arr class. So feel free to add the following to your alias list in the file `/app/config/app.php`:

```
'Arr' => 'Gears\Arrays',
```

> Also note that `Gears\Arrays\Fluent` is again compaitible with the standard `Illuminate\Support\Collection` class.

Credits
-------

[](#credits)

Thanks to *axelarge* for the inspiration, I have taken his methods re-factored them slightly and added a few of my own methods, into the mix.

Additionally all methods in the class `Illuminate\Support\Arr`provided by Laravel. Have been integrated into `Gears\Array`.

Also from Laravel `Illuminate\Support\Collection`, our fluent interface extends this class. Some have refered to the Laravel Collection class as Arrays on steriods. So I am not sure what you would call our fluent class. *Arrays on INSERT HARD CORE DRUG HERE*...

---

Developed by Brad Jones -

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity59

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

Every ~55 days

Recently: every ~32 days

Total

10

Last Release

4164d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2754772?v=4)[Brad Jones](/maintainers/brad-jones)[@brad-jones](https://github.com/brad-jones)

---

Top Contributors

[![brad-jones](https://avatars.githubusercontent.com/u/2754772?v=4)](https://github.com/brad-jones "brad-jones (5 commits)")

---

Tags

arraymanipulation

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M342](/packages/psalm-plugin-laravel)[renatomarinho/laravel-page-speed

Laravel Page Speed

2.5k1.7M11](/packages/renatomarinho-laravel-page-speed)[illuminate/pagination

The Illuminate Pagination package.

12234.1M1.0k](/packages/illuminate-pagination)[illuminate/pipeline

The Illuminate Pipeline package.

9349.2M275](/packages/illuminate-pipeline)[illuminate/broadcasting

The Illuminate Broadcasting package.

7127.2M208](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

9014.6M369](/packages/illuminate-redis)

PHPackages © 2026

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