PHPackages                             shadiakiki1986/array-utils - 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. shadiakiki1986/array-utils

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

shadiakiki1986/array-utils
==========================

Useful functions for working with arrays

2.0.5(9y ago)0892MITPHPPHP &gt;=7

Since Jan 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/shadiakiki1986/php-array-utils)[ Packagist](https://packagist.org/packages/shadiakiki1986/array-utils)[ RSS](/packages/shadiakiki1986-array-utils/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (5)Versions (9)Used By (0)

ArrayUtils
==========

[](#arrayutils)

ArrayUtils is a collection of useful PHP array functions.

[![Build Status](https://camo.githubusercontent.com/b97c0227490b237251293c87681c8e1b2f81a4be12316d095d7550d2d7697e9d/68747470733a2f2f7472617669732d63692e6f72672f7368616469616b696b69313938362f7068702d61727261792d7574696c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/shadiakiki1986/php-array-utils)[Packagist](https://packagist.org/packages/shadiakiki1986/array-utils)

This is a fork of [theodorejb/array-utils](https://github.com/theodorejb/array-utils): [![Packagist Version](https://camo.githubusercontent.com/7b48e7b1f57e0a09bd76b1177bcd8f66515381f9809725158f068acfe80a05d4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7468656f646f72656a622f61727261792d7574696c732e737667)](https://packagist.org/packages/theodorejb/array-utils) [![License](https://camo.githubusercontent.com/c221a24abcda03804843c53ece53089fc7ece4ca0ff63fbe44ad16a8f3cd1a61/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7468656f646f72656a622f61727261792d7574696c732e737667)](https://packagist.org/packages/theodorejb/array-utils) [![Build Status](https://camo.githubusercontent.com/41741389c41388dfee5c8814a6fcc966a790d06156af3c17d9e84ba21f06201b/68747470733a2f2f7472617669732d63692e6f72672f7468656f646f72656a622f61727261792d7574696c732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/theodorejb/array-utils)

Major changes are that I require `php>=7` for the sake of the parameter types in `CellCounterManager` functions

Install via Composer
--------------------

[](#install-via-composer)

`composer require shadiakiki1986/array-utils`

and add bootstrap

`require_once __DIR__."/vendor/autoload.php";`

Functions
---------

[](#functions)

### contains\_all

[](#contains_all)

Returns true if all the needles are in the haystack.

```
use function theodorejb\ArrayUtils\contains_all;

$haystack = [1, 2, 3, 5, 8, 13];
$needles = [2, 13, 5];
echo contains_all($needles, $haystack); // true
echo contains_all($haystack, $needles); // false
```

### contains\_same

[](#contains_same)

Returns true if both arrays contain the same values (regardless of order).

```
use function theodorejb\ArrayUtils\contains_same;

$set1 = [1, 3, 5, 7];
$set2 = [3, 7, 5, 1];

echo contains_same($set1, $set2); // true
```

### group\_rows

[](#group_rows)

Splits the array of associative arrays into groups when the specified key value changes. The array must be sorted by the array key used to group results.

```
use function theodorejb\ArrayUtils\group_rows;

// obtained by joining tables of people and their pets
$peoplePets = [
    ['name' => 'Jack', 'petName' => 'Scruffy'],
    ['name' => 'Jack', 'petName' => 'Spot'],
    ['name' => 'Jack', 'petName' => 'Paws'],
    ['name' => 'Amy', 'petName' => 'Blackie'],
    ['name' => 'Amy', 'petName' => 'Whiskers']
];

$grouped = [];

foreach (group_rows($peoplePets, 'name') as $group) {
    $grouped[] = $group;
}

$expected = [
    [
        $peoplePets[0],
        $peoplePets[1],
        $peoplePets[2],
    ],
    [
        $peoplePets[3],
        $peoplePets[4],
    ]
];

var_dump($grouped === $expected); // bool(true)
```

### array3d2xlsx

[](#array3d2xlsx)

Dumps array of arrays as xlsx file, with each subarray as a sheet

Requires `apt-get install php-zip` and `composer require PHPOffice/PHPExcel`

```
use shadiakiki1986\ArrayUtils\Converters;

// obtained by joining tables of people and their pets
$peoplePets = [
    ['name' => 'Jack', 'petName' => 'Scruffy'],
    ['name' => 'Jack', 'petName' => 'Spot'],
    ['name' => 'Jack', 'petName' => 'Paws'],
    ['name' => 'Amy', 'petName' => 'Blackie'],
    ['name' => 'Amy', 'petName' => 'Whiskers']
];

var_dump(Converters::array3d2xlsx(array("people-pets"=>$peoplePets))); // returns path to xlsx filename in temporary directory
```

For excel dates in the cells, use the \\DateTime class for the php values, e.g.

```
$people = [
    ['name' => 'Roula', 'dateOfBirth' => \DateTime::createFromFormat('!Y-m-d','1982-10-05')],
    ['name' => 'Shadi', 'dateOfBirth' => \DateTime::createFromFormat('!Y-m-d','1986-09-22')]
];

```

Note the `!` preceding `Y-m-d` above resets the hours/minutes/seconds to 0 so that they don't show up in the excel data autofilter. Check the docs for [DateTime::createFromFormat](http://php.net/manual/en/datetime.createfromformat.php) for more details.

Memory issues:

- for large excel files, phpexcel could run out of memory (check [here](https://github.com/PHPOffice/PHPExcel/blob/1c8c2379ccf5ab9dd7cb46be965821d22173bcf4/Documentation/markdown/Overview/04-Configuration-Settings.md))
- Need `apt-get install sqlite3`
- pass `true` for the `isLarge` (2nd) parameter to `array3d2xlsx`

### array2console

[](#array2console)

Dumps a 3d array to a string in tabular format for viewing in the console

```
use shadiakiki1986\ArrayUtils\Converters;

// obtained by joining tables of people and their pets
$peoplePets = [
    ['name' => 'Jack', 'petName' => 'Scruffy'],
    ['name' => 'Jack', 'petName' => 'Spot'],
    ['name' => 'Jack', 'petName' => 'Paws'],
    ['name' => 'Amy', 'petName' => 'Blackie'],
    ['name' => 'Amy', 'petName' => 'Whiskers']
];

echo(Converters::array2console($peoplePets)); // outputs array in tabular format
```

### array2html

[](#array2html)

Dumps a 3d array to a html string in tabular format for viewing in a browser

```
use shadiakiki1986\ArrayUtils\Converters;

// obtained by joining tables of people and their pets
$peoplePets = [
    ['name' => 'Jack', 'petName' => 'Scruffy'],
    ['name' => 'Jack', 'petName' => 'Spot'],
    ['name' => 'Jack', 'petName' => 'Paws'],
    ['name' => 'Amy', 'petName' => 'Blackie'],
    ['name' => 'Amy', 'petName' => 'Whiskers']
];

echo(Converters::array2html($peoplePets)); // outputs array in html table
```

Author
------

[](#author)

Theodore Brown

Shadi Akiki

License
-------

[](#license)

MIT

Dev notes
---------

[](#dev-notes)

If `phpcs` reports errors that can be fixed automatically, run `vendor/bin/phpcbf src/` and then commit the changes

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

Established project with proven stability

 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 ~44 days

Recently: every ~22 days

Total

9

Last Release

3465d ago

Major Versions

v1.1.0 → 2.0.02016-10-07

PHP version history (2 changes)v1.0.0PHP &gt;=5.6

2.0.3PHP &gt;=7

### Community

Maintainers

![](https://www.gravatar.com/avatar/2cc997a8672e96aaee90c8555b7e5bc9693894e74c7530abf2216ee6799357ff?d=identicon)[shadiakiki1986](/maintainers/shadiakiki1986)

---

Top Contributors

[![shadiakiki1986](https://avatars.githubusercontent.com/u/8392324?v=4)](https://github.com/shadiakiki1986 "shadiakiki1986 (29 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/shadiakiki1986-array-utils/health.svg)

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

###  Alternatives

[terminal42/contao-mp_forms

An extension for Contao Open Source CMS to create multi steps forms using the form generator

2534.7k6](/packages/terminal42-contao-mp-forms)

PHPackages © 2026

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