PHPackages                             phiil/xtraverse - 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. phiil/xtraverse

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

phiil/xtraverse
===============

PHP bundle wich makes array traversing / inserting dead easy.

1.1(4y ago)24MITPHPPHP ^7.4|^8.0

Since Oct 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/philipp-riddle/xtraverse.php)[ Packagist](https://packagist.org/packages/phiil/xtraverse)[ RSS](/packages/phiil-xtraverse/feed)WikiDiscussions master Synced 3w ago

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

XTraverse.php
=============

[](#xtraversephp)

This bundle makes it dead easy to traverse through nested arrays/objects in PHP.

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

[](#installation)

### Via Composer

[](#via-composer)

```
composer require phiil/xtraverse

```

### File download

[](#file-download)

To use all the functions of this package simply download the `src/` directory.

Getting started
---------------

[](#getting-started)

### Traversing paths

[](#traversing-paths)

Paths are how you specify where you want to traverse to inside the nested object. Let's assume you want to get the title of the Block with ID 1 inside the 'blocks' array.

Our nested object:

```
$data = [
    'blocks' => [
        [
            'id' => 1,
            'title' => 'First block',
        ],
    ],
];
```

Now we specify which element we want:

```
$path = 'blocks[1].title';
```

Every step is delimited with a dot ('.') - if you want to query for an ID simply append it to the path with closed brackets.

Now let the traversing begin:

```
use Phiil\XTraverse\Traverser;

$traverser = new Traverser();
$title = $traverser->traverseData($path, $data, traverseArrayLimit: false); // we want a non-array value - pass "false" as the last argument or the service will throw an exception

echo $title;
```

The above will output the following: `First block`

### Updating a nested value

[](#updating-a-nested-value)

Updating a value also works with paths:

```
use Phiil\XTraverse\Traverser;

// We want to update the title of the block we previously traversed to
$updatePath = 'blocks[1].title';

$traverser = new Traverser();
$data = $traverser->update($data, $path, 'New title')->data;
```

**Note:** The update method returns an object with the properties `path`, `data` &amp; `insert`. Getting the data property from the object straight away is almost always the best option.

### Working with IDs

[](#working-with-ids)

The traverse service can auto-increment IDs - meaning if you insert a nested object like:

```
use Phiil\XTraverse\Traverser;

$object = [
    'id' => null,
    'title' => 'Second block',
];
$traverser = new Traverser();
$data = $traverser->update($object, 'blocks.$', $object)->data;
```

The object inside `$data` will now have the ID of 2 (First Block: ID 1).

**Note:** The `path.$` syntax can be used if you want to add a block to a non-associative (only numeric keys) array.

Running tests
-------------

[](#running-tests)

To run tests run the following commands:

```
composer install --dev
./vendor/bin/phpunit tests/

```

Problems? Issues?
-----------------

[](#problems-issues)

Just post them here on Github or contact me via email: . Feel free to contribute!

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

1563d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/26253126?v=4)[Phil Young Xu](/maintainers/phiil)[@Phiil](https://github.com/Phiil)

---

Top Contributors

[![philipp-riddle](https://avatars.githubusercontent.com/u/53085316?v=4)](https://github.com/philipp-riddle "philipp-riddle (5 commits)")

---

Tags

nested-arraysnested-objectsphpphp7traversetreetreetraversenested objects

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/phiil-xtraverse/health.svg)

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

###  Alternatives

[knplabs/knp-menu

An object oriented menu library

1.4k58.1M339](/packages/knplabs-knp-menu)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k13.2M174](/packages/cuyz-valinor)[bluem/tree

Library for handling tree structures based on parent IDs

251953.3k7](/packages/bluem-tree)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329530.5k29](/packages/codewithdennis-filament-select-tree)[loophp/phptree

An implementation of tree data structure

981.8M2](/packages/loophp-phptree)[maxazan/jquery-treegrid

jquery treegrid plugin

55754.6k](/packages/maxazan-jquery-treegrid)

PHPackages © 2026

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