PHPackages                             gupalo/arrayutils - 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. gupalo/arrayutils

ActiveLibrary

gupalo/arrayutils
=================

Array utils

1.11.0(4mo ago)014.6k↓16.7%1MITPHPPHP &gt;=8.4

Since Jan 20Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/gupalo/arrayutils)[ Packagist](https://packagist.org/packages/gupalo/arrayutils)[ RSS](/packages/gupalo-arrayutils/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (19)Used By (1)

ArrayUtils
==========

[](#arrayutils)

Install
-------

[](#install)

```
composer require gupalo/arrayutils
```

Features
--------

[](#features)

All code is covered by tests. Look at tests to understand better how it's working.

All methods are static.

Items can be iterable (array, \\Generator, ...) of one of:

- array
- object with public properties or getters (anything Symfony PropertyAccessor can get)

ArrayAggregator
---------------

[](#arrayaggregator)

- `max(items, field)`: max field value among items
- `sum(items, field)`: sum of field values of items
- `ratio(items, field, field2`: `"sum by field"/"sum by field2"`
- `maxRatio(items, field, field2)`: max among `"field value"/"field value2"`

ArrayComparer
-------------

[](#arraycomparer)

Comparing is smart - if compared values are float, they are rounded with precision = 8.

- `compareOne(a1, a2, keys)`: check that each `(string)a1[key] === (string)a2[key]` for each of keys. returns "patch" how to go from a1 to a2. `null` value means that we need to unset this key.
- `compare(a1, a2, keys)`a1 and a2 are expected to be array of arrays. returns patch how what's changed in a2 compared to a1 - array with keys:
    - `created`: which items should be created and their values
    - `updated`: which items should be updated and updated fields
    - `removed`: which items (ids) should be deleted
- `compareFlat(a1, a2)`similar to `compare` but a1 and a2 are considered scalars and are compared fully, not by fields

ArrayFactory
------------

[](#arrayfactory)

- `createKeys(keys, value)`: create array with these keys and value
- `createDictionary(a, keyColumn, valueColumn)`: similar to `array_column(a, valueColumn, keyColumn)` but doesn't require values present in all items (`?? null`)

ArrayKeysHelper
---------------

[](#arraykeyshelper)

- `index($a, array|string $keys = 'id')`: create indexed array where index may contain several fields
- `indexAndGroup($a, array|string $keys = 'id')`: create indexed array but allow several items with same index
- `fill($a, $keys, $defaultValue = null)`: ensure that all keys exist in array and all others are missing
- `filter($a, $keys, $createMissingKeys = true)`: get these keys from array
- `unset($a, $keys)`: unset these keys from each array item

ArrayRandom
-----------

[](#arrayrandom)

- `pick(array $items)`: select random value from array
- `pickMultiple(array $items, int $count = 1, bool $preserveKeys = false, mixed $default = [])`: select multiple ($count) random values from array

ArrayTable
----------

[](#arraytable)

- `arrayToKeyValues(array $data)`: covert table (like TSV; first item is header with keys) to array with named keys

ArrayUniquer
------------

[](#arrayuniquer)

- `values(array $a)`: uniq -&gt; values
- `notNullValues(array $a)`: filter not null -&gt; uniq -&gt; values
- `columnValues(array $a, string $column)`: column -&gt; uniq -&gt; values
- `mergeValues(...$a)`: merge -&gt; uniq -&gt; values
- `mergeNotNullValues(...$a)`: merge -&gt; filter not null -&gt; uniq -&gt; values

FloatArrayFactory
-----------------

[](#floatarrayfactory)

- `createPreserveKeys(array $a)`: ensure that all values are float
- `create(array $a)`: ensure that all values are float -&gt; values

IntArrayFactory
---------------

[](#intarrayfactory)

- `createPreserveKeys(array $a)`: ensure that all values are int
- `create(array $a)`: ensure that all values are int -&gt; values

Balancer
--------

[](#balancer)

Problem to solve: you have some items and need to split them to some buckets. You may configure different strategies how to distribute your items between the buckets. Buckets should implement `BucketInterface`, balancer should implement `BalancerInterface`

### SemiRandomBalancer

[](#semirandombalancer)

It's not fully random, you set seed so multiple runs with the same seed and same items will lead to the same result.

### FairBalancer

[](#fairbalancer)

Try to make same weighted count of items in same bucket.

Example: A/B test where you want to send 90% of users to "A" page and 10% to "B" page. You could use simple random but with low amount of users it's quite probable that you have 20 users and all will see page "A" or 5 users that go to "B". Then you'll have hard time explaining probability theory. With this balancer you may be sure that 1 of the first 10 users will go to "B" and most probably 2 of 20 users will land there.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance76

Regular maintenance activity

Popularity25

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 77.3% 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 ~96 days

Recently: every ~252 days

Total

16

Last Release

129d ago

PHP version history (2 changes)1.0PHP &gt;=8.0

1.11.0PHP &gt;=8.4

### Community

Maintainers

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

---

Top Contributors

[![luchaninov](https://avatars.githubusercontent.com/u/3829796?v=4)](https://github.com/luchaninov "luchaninov (17 commits)")[![Okspen](https://avatars.githubusercontent.com/u/388928?v=4)](https://github.com/Okspen "Okspen (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gupalo-arrayutils/health.svg)

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

###  Alternatives

[symfony/form

Allows to easily create, process and reuse HTML forms

2.8k152.1M2.8k](/packages/symfony-form)[symfony/security-http

Symfony Security Component - HTTP Integration

1.7k164.3M234](/packages/symfony-security-http)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k48.1M236](/packages/api-platform-core)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[vich/uploader-bundle

Ease file uploads attached to entities

1.9k25.9M116](/packages/vich-uploader-bundle)

PHPackages © 2026

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