PHPackages                             rugolinifr/array-path-selector - 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. rugolinifr/array-path-selector

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

rugolinifr/array-path-selector
==============================

This package provides an API to flatten nested PHP arrays to map their values to a path selector, do the opposite operation or replace any value in the array.

v1.1.0(1mo ago)02↓75%MITPHPPHP 8.\*

Since Jul 12Pushed 1mo agoCompare

[ Source](https://github.com/rugolinifr/array-path-selector)[ Packagist](https://packagist.org/packages/rugolinifr/array-path-selector)[ RSS](/packages/rugolinifr-array-path-selector/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Array path selector
===================

[](#array-path-selector)

This package provides an API to flatten nested PHP arrays to map their values to a path selector, do the opposite operation or replace any value in the array.

Installation
------------

[](#installation)

Run the following command:

```
composer require rugolinifr/array-path-selector
```

Flattener examples
------------------

[](#flattener-examples)

Instantiate the API object:

```
$flattener = (new Rugolinifr\ArrayPathSelector\Factory\PathToolFactory())->createFlattener();
```

Then create an array (looking like a regular JSON object in the following example):

```
$array = [
    'name' => 'John Doe',
    'address' => [
        'city' => 'Nice',
        'zips' => [
            '06000',
            '06100',
        ],
        'street' => 'Promenade des anglais',
    ],
    'birth' => new DateTimeImmutable('1980-01-01 12:00:00'),
    'kids' => [],
];
```

Then flatten an array according to the "key/value" model:

```
// flatten an array following the "key/value" model:
$keyValues = $flattener->flattenAsKeyValues($array);
$keyValues === [
    'name' => 'John Doe',
    'address.city' => 'Nice',
    'address.zips[0]' => '06000',
    'address.zips[1]' => '06100',
    'address.street' => 'Promenade des anglais',
    'birth' => new DateTimeImmutable('1980-01-01 12:00:00'),
    'kids' => [], //empty arrays have their own entry, otherwise they would disappear from the flattened array
];
```

Or following the "pairing" model:

```
$pairs = $flattener->flattenAsPairs($array);
$keyValues === [
    0 => ['name', 'John Doe'],
    1 => ['address.city', 'Nice'],
    2 => ['address.zips[0]', '06000'],
    3 => ['address.zips[1]', '06100'],
    4 => ['address.street', 'Promenade des anglais'],
    5 => ['birth', new DateTimeImmutable('1980-01-01 12:00:00')],
    6 => ['kids', []], //empty arrays have their own entry, otherwise they would disappear from the flattened array
];
```

The "key/value" model is the more natural approach, perfect to test whether a path existence or find a value, whereas the "pairing" model suits better when comparing the subparts of two (or more) arrays is wanted, as sequential numeric keys are easier to follow than a recursive comparison algorithm.

Crud examples
-------------

[](#crud-examples)

Instantiate the API object:

```
$crud = (new Rugolinifr\ArrayPathSelector\Factory\PathToolFactory())->createCrud();
```

Then use it to manipulate arrays:

```
$array = [
    'name' => 'John Doe',
    'kids' => [],
];

// Create new arrays along the property path:
$crud->put($array, 'address.city', 'Nice');
$crud->put($array, 'address.zips[0]', '06000');

$array === [
    'name' => 'John Doe',
    'kids' => [],
    'address' => [
        'city' => 'Nice',
        'zips' => [
            '06000',
        ],
    ],
];

// Get a value:
$crud->get($array, 'name') === 'Jane Doe';

// Replace a value:
$crud->put($array, 'name', 'Jane Doe');

// Delete a value:
$crud->delete($array, 'kids');
$crud->delete($array, 'address.zips[0]');

$array === [
    'name' => 'Jane Doe',
    'address' => [
        'city' => 'Nice',
        'zips' => [],
    ],
];
```

Known limitations
-----------------

[](#known-limitations)

Arrays having keys using the dot character of wrapping integers with squared brackets will conflicts with this API.

For maintainers
---------------

[](#for-maintainers)

The project is shipped with a development image:

```
docker compose up -d --build --force-recreate
```

Use it to test the project:

```
docker compose exec php phpstan analyze
docker compose exec php vendor/bin/phpunit tests
```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance91

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

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

Total

3

Last Release

42d ago

### Community

Maintainers

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

---

Top Contributors

[![rugolinifr](https://avatars.githubusercontent.com/u/55209838?v=4)](https://github.com/rugolinifr "rugolinifr (8 commits)")

---

Tags

phparraypathselectorarray\_walk\_recursive

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rugolinifr-array-path-selector/health.svg)

```
[![Health](https://phpackages.com/badges/rugolinifr-array-path-selector/health.svg)](https://phpackages.com/packages/rugolinifr-array-path-selector)
```

###  Alternatives

[zakirullin/mess

Convenient array-related routine &amp; better type casting

21331.4k2](/packages/zakirullin-mess)

PHPackages © 2026

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