PHPackages                             simbiat/arrayhelpers - 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. simbiat/arrayhelpers

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

simbiat/arrayhelpers
====================

Set of useful functions to work with arrays

4.0.0+20260411(1mo ago)0521AGPL-3.0-or-laterPHPPHP ^8.4

Since Dec 19Pushed 3w ago1 watchersCompare

[ Source](https://github.com/Simbiat/ArrayHelpers)[ Packagist](https://packagist.org/packages/simbiat/arrayhelpers)[ Docs](https://github.com/Simbiat/ArrayHelpers)[ RSS](/packages/simbiat-arrayhelpers/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (10)DependenciesVersions (25)Used By (1)

Array Helpers
=============

[](#array-helpers)

Set of useful functions to work with arrays, split into classes based on the type of operation.

Checkers
--------

[](#checkers)

Functions to check if something is true or not.

### isMultiDimensional

[](#ismultidimensional)

```
\Simbiat\ArrayHelpers\Checkers::isMultiDimensional(array $array, bool $equal_length = false, bool $all_scalar = false);
```

Checks if an array is multidimensional, essentially if all of its values are arrays. If `$equal_length` is `true`, will also check that all the arrays are of the same length and will throw an error if it's not the case. If `$all_scalar` is `true`, and the array is *not* multidimensional, the function will also check if all values in the array are scalar, and throw an error if at least one of them is not.

### isAssociative

[](#isassociative)

```
\Simbiat\ArrayHelpers\Checkers::isAssociative(array $array);
```

Checks if an array is associative, that is if there is at least one key that's a string (PHP will convert numeric keys to integers by design and will not allow other data types).

### isAllScalar

[](#isallscalar)

```
\Simbiat\ArrayHelpers\Checkers::isAllScalar(array $array);
```

Checks if an array consists only of scalar values or not.

### getChanges

[](#getchanges)

```
\Simbiat\ArrayHelpers\Checkers::getChanges(array $old, array $new);
```

Get list of changes in the new array compared to the old one. Result will be an array looking like this:

```
[
    'key1' => [
        'from' => 'old_value',
        'to' => 'new_value'
    ],
    'key2' => [
        'from' => 'old_value',
        'to' => 'new_value'
    ],
]
```

If a key is missing in old or new array `null` will be used for respective `from` or `to` value.

Converters
----------

[](#converters)

Functions to convert something to something else.

### multiToSingle

[](#multitosingle)

```
\Simbiat\ArrayHelpers\Converters::multiToSingle(array $old_array, string $key_to_save);
```

Converts a multidimensional array to "flat" (or "flatter") one. Essentially a `array_column`, but also uses `array_combine` and `array_keys` to preserve the keys.

### dbfToArray

[](#dbftoarray)

```
\Simbiat\ArrayHelpers\Converters::dbfToArray(string $file);
```

Converts contents of a [DBF](https://en.wikipedia.org/wiki/.dbf) file to an array.

### attributesToArray

[](#attributestoarray)

```
\Simbiat\ArrayHelpers\Converters::attributesToArray(\DOMNode|Node $node, bool $null = true, array $extra_attributes = []);
```

Converts `\DOMNode` or `\Dom\Node` into an array with a set of attributes, present in the node, as the array's keys. If `$null` is set to `true` empty attributes will be replaced with `null` (instead of empty string). You can also pass a list of attributes in `$extra_attributes`, which will be added to all resulting elements, if they do not have that attribute. Extra attributes are added as either an empty string or a `null` if `$null` is `true`.

### toMultiArray

[](#tomultiarray)

```
\Simbiat\ArrayHelpers\Converters::toMultiArray(array $array, array $keys);
```

Turns a regular array to a multidimensional one by turning provided keys into one of the columns. It will turn an array like

```
[
    'apple' => 1,
    'banana' => 2,
]
```

To an array like

```
[
    [
        'name' => 'apple',
        'value' => 1
    ],
    [
        'name' => 'banana',
        'value' => 2
    ],
]
```

if you provide the below array as `$keys`:

```
[
    'name',
    'value',
]
```

### arrayToProperties

[](#arraytoproperties)

```
\Simbiat\ArrayHelpers\Converters::arrayToProperties(object $object, array $array, array $skip = [], bool $strict = true);
```

"Converts" an array to an object's properties (just sets their values to those from the array). Useful when you need to populate them based on results from some function, for example, a `SELECT` from database. Only values with string keys will be processed.

If `$skip` array is passed to the function and a key from `$array` is present there, it will be skipped. If `$strict` is set to `true`, and a property does not exist in the object, an exception will be thrown.

### enumValues

[](#enumvalues)

```
\Simbiat\ArrayHelpers\Converters::enumValues(string $enum);
```

Gets either list of cases' values from a backed enum. `$enum` is expected to be something like `\Path\To\Enum::class`.

### enumNames

[](#enumnames)

```
\Simbiat\ArrayHelpers\Converters::enumNames(string $enum);
```

Gets either list of cases' names an enum. `$enum` is expected to be something like `\Path\To\Enum::class`.

Editors
-------

[](#editors)

Functions that somehow edit the array content.

### digitToKey

[](#digittokey)

```
\Simbiat\ArrayHelpers\Editors::digitToKey(array $old_array, string $new_key, bool $key_unset = false);
```

Replaces a multidimensional array's values with values from a specific column. With PHP updates this has become a wrapper for `array_column`, but `$key_unset` set to `true` allows you to remove the chose column after rekeying.

### ColumnsConversion

[](#columnsconversion)

```
\Simbiat\ArrayHelpers\Editors::columnsConversion(array $array, array|string $columns, string $type = 'int');
```

Allows casting values in a column (or set of columns) to a specific type. Supported values for `$type` are: `int`/`integer`, `bool`/`boolean`, `float`/`double`/`real`, `string`, `array`, `object`. Casting is done by native functions.

### RemoveByValue

[](#removebyvalue)

```
\Simbiat\ArrayHelpers\Editors::removeByValue(array $array, mixed $remove_value, bool $rekey = false);
```

Simple function that removes all elements with a certain value (`$remove_value`) and optionally re-keys it if `$rekey` is `true (useful for an indexed array, useless for associative ones).

### setKeyPath

[](#setkeypath)

```
\Simbiat\ArrayHelpers\Editors::setKeyPath(array $array, array $path, mixed $value);
```

Allows recursively setting a key path based on logic from [StackOverflow](https://stackoverflow.com/a/5821027/2992851). Useful for "generating" arrays of a specific shape or updating existing ones.
`$path` is an array where each key is part of a new path with format like this:

```
['new', 'path']
```

It is meant to be "converted" and result in

```
$array['new']['path']);
```

Parts of the path are created only if they are not present already.
`$value` is the value that will be assigned to the newly created path. `$array` is passed by reference.

### moveToSubarray

[](#movetosubarray)

```
\Simbiat\ArrayHelpers\Editors::moveToSubarray(array $array, string|int $key, array $new_key_path);
```

Function to move keys into a subarray. For example, you have a key like `$array['key']`, but you want to remove it and have it as `$array['subarray']['key']` - then use this function. Purely for data formatting.
`$new_key_path` requires the same format as `$path` in `setKeyPath()`. `$array` is passed by reference.

### renameColumn

[](#renamecolumn)

```
\Simbiat\ArrayHelpers\Editors::renameColumn(array $array, string $column, string $key_name);
```

Rename a column in a multidimensional array. `$array` is passed by reference.

Sorters
-------

[](#sorters)

Functions to sort arrays (just one for now).

### multiArrSort

[](#multiarrsort)

```
\Simbiat\ArrayHelpers\Sorters::multiArrSort(array $array, string $column, bool $desc = false);
```

Function to sort a multidimensional array by values in a column. Can be "reversed" to sort from larger to smaller (descending order), if `$desc` is set to `true`.

### recursiveSort

[](#recursivesort)

```
\Simbiat\ArrayHelpers\Sorters::recursiveSort(array &$array, bool $key = false, bool $desc = false, int $sort_flag = \SORT_REGULAR);
```

Function to recursively sort array using `sort`, `rsort`, `ksort` or `krsort` depending on respective values of `$key` and `$desc` arguments.

Splitters
---------

[](#splitters)

Functions to split arrays into parts.

### topAndBottom

[](#topandbottom)

```
\Simbiat\ArrayHelpers\Splitters::topAndBottom(array $array, int $rows = 0);
```

Function that splits the array to 2 representing first X and last X rows from it, providing a way to get "Top X" and its counterpart. If `$rows` is less than `1` or the array size is less than `$rows * 2`, then function will try to split the array evenly. Resulting array will have `top` and `bottom` keys with respective rows, but if the array has only one element, an exception will be thrown.

### splitByKey

[](#splitbykey)

```
\Simbiat\ArrayHelpers\Splitters::splitByKey(array $array, string $column_key, array $new_keys = [], bool $keep_key = false, bool $case_insensitive = false);
```

Splits a multidimensional array by values from a column. Useful to reduce the number of travels to a database. Instead of doing 2+ queries separately, we do just one query and then split the results to several arrays in code. Turns an array like this:

```
[
    [
        'type' => 'int',
        'value' => 1,
    ],
    [
        'type' => 'int',
        'value' => 2,
    ],
    [
        'type' => 'string',
        'value' => '1',
    ],
    [
        'type' => 'string',
        'value' => '1',
    ],
]
```

to this:

```
[
    'int' => [
        ['value' => 1],
        ['value' => 2],
    ],
    'string' => [
        ['value' => '1'],
        ['value' => '2'],
    ]
]
```

If `$keep_key` is set to `true` will retain the original column in all the rows. If `$case_insensitive` is `true` will do `mb_strtolower()` on all the keys from the column to ensure correct splitting (that's the case where you *may* want to retain the original value of the key, too).
If `$new_keys` is empty (default), then `array_column` will be used to get the keys for the resulting array. However, if a list of integers or strings (or mix, which is not recommended) is provided, it will act as a filter, discarding rows, which have the column's value, that's not in the list.

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance94

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

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

Recently: every ~106 days

Total

24

Last Release

37d ago

Major Versions

1.0.3+20201227 → 2.0.0+202103102021-03-10

2.4.8+20250209 → 3.0.0+202504132025-04-13

3.0.2+20250423 → 4.0.0+202604112026-04-11

PHP version history (4 changes)1.0.0+20201219PHP ^7.4

2.0.0+20210310PHP ^8

2.4.2+20240407PHP ^8.3

3.0.1+20250417PHP ^8.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6022665?v=4)[Dmitrii Kustov](/maintainers/Simbiat)[@Simbiat](https://github.com/Simbiat)

---

Top Contributors

[![Simbiat](https://avatars.githubusercontent.com/u/6022665?v=4)](https://github.com/Simbiat "Simbiat (7 commits)")

---

Tags

phphelperarray

### Embed Badge

![Health badge](/badges/simbiat-arrayhelpers/health.svg)

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

###  Alternatives

[zjkal/time-helper

一个简单快捷的PHP日期时间助手类库。 a smart PHP datetime helper library.

21128.6k1](/packages/zjkal-time-helper)[clausnz/php-helpers

A Collection of useful php helper functions.

388.7k](/packages/clausnz-php-helpers)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)[bayfrontmedia/php-array-helpers

Helper class to provide useful array functions.

1413.4k23](/packages/bayfrontmedia-php-array-helpers)

PHPackages © 2026

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