PHPackages                             pflorek/elevator - 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. pflorek/elevator

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

pflorek/elevator
================

Flattens a multi-dimensional array or any \\Traversable into a one-dimensional array. Elevates an one-dimensional or any \\Traversable to a multi-dimensional array.

2.0.1(9y ago)017.3k↓16.7%1MITPHPPHP &gt;=5.4

Since Mar 17Pushed 6y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (2)Versions (7)Used By (1)

PHP Elevator
============

[](#php-elevator)

[![Build Status](https://camo.githubusercontent.com/0db1aaf188459150be96c1c2140e0991bb0cfd1220c106dd46ecdc80ef7b9c87/68747470733a2f2f7472617669732d63692e6f72672f70666c6f72656b2f7068702d656c657661746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/pflorek/php-elevator)[![Coverage Status](https://camo.githubusercontent.com/56fc3cd88fb43dea0d5393565bab3d39b013d9c86f4fa05e0755e92f1c3edca0/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f70666c6f72656b2f7068702d656c657661746f722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/pflorek/php-elevator?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/0a9fa1f3b2357c7851aaf7a5f2cd5629f4bf5c2f85ce365188de1fa6156a5016/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f70666c6f72656b2f7068702d656c657661746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/pflorek/php-elevator/?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/bb3327f1626bd0881688fd9555684e52b74ebc0175a6b443eecf15a77344fbf9/68747470733a2f2f706f7365722e707567782e6f72672f70666c6f72656b2f656c657661746f722f762f737461626c65)](https://packagist.org/packages/pflorek/elevator)[![Total Downloads](https://camo.githubusercontent.com/b276e65e8f127f33e783dfea60830ca6e6d87e6dee0a2e6621258899af9643ef/68747470733a2f2f706f7365722e707567782e6f72672f70666c6f72656b2f656c657661746f722f646f776e6c6f616473)](https://packagist.org/packages/pflorek/elevator)[![Latest Unstable Version](https://camo.githubusercontent.com/0125a7016931c1c2b7a984192042a27a630f1d7b1655393c88b34e27b891684d/68747470733a2f2f706f7365722e707567782e6f72672f70666c6f72656b2f656c657661746f722f762f756e737461626c65)](https://packagist.org/packages/pflorek/elevator)[![License](https://camo.githubusercontent.com/4134cb8299d89fb322119bc1a096025a6ffef507d91c9189cc7817a18cc13bf6/68747470733a2f2f706f7365722e707567782e6f72672f70666c6f72656b2f656c657661746f722f6c6963656e7365)](https://packagist.org/packages/pflorek/elevator)[![Monthly Downloads](https://camo.githubusercontent.com/af3d10e85aac4728413d41c1ff7f3f3c00189708b6631e9f9ffc151f410af5d2/68747470733a2f2f706f7365722e707567782e6f72672f70666c6f72656b2f656c657661746f722f642f6d6f6e74686c79)](https://packagist.org/packages/pflorek/elevator)[![Daily Downloads](https://camo.githubusercontent.com/79c7adf66bbbb098a5e66771afcef753b0033dbfea2bec283100bc4240a8689a/68747470733a2f2f706f7365722e707567782e6f72672f70666c6f72656b2f656c657661746f722f642f6461696c79)](https://packagist.org/packages/pflorek/elevator)[![composer.lock](https://camo.githubusercontent.com/d5be1039672886706db524f77971b92fd832c5efda19279bbb6ef9b1287fa998/68747470733a2f2f706f7365722e707567782e6f72672f70666c6f72656b2f656c657661746f722f636f6d706f7365726c6f636b)](https://packagist.org/packages/pflorek/elevator)

This library provides a simple way to elevate a map (associative array) to a tree or to flatten a tree to a map (associative array). The tree's node keys are the tokens of the map's materialized path separated by a delimiter.

This library comes handy to map flat lists like SQL results to documents. The result's column name could be a materialized path of the target document. You can pass a result row to `Elevator::up` and proceed marshalling by passing the elevated tree to a JSON or XML serializer. On unmarshalling just pass the deserialized array tree to `Elevator::down` and feed e.g. a SQL statement.

Usage
-----

[](#usage)

### Elevate

[](#elevate)

Elevate a map with materialized paths to a tree:

```
use PFlorek\Elevator\Elevator;
use PFlorek\Elevator\ElevatorFactory;
use function \PFlorek\Elevator\array_elevate;

$flattened = [
    'World.Asia.Afghanistan.0' => '...',
    'World.Africa' => true,
    'World.Antarctica' => -25.2,
    'World.Europe' => new \stdClass(),
    'World.North America' => [],
];

// object oriented
$factory = ElevatorFactory::getInstance();
$elevator = $factory->create();
$elevator->up($flattened);

// or functional
$elevated = array_elevate($flattened);

var_dump($elevated);

//returns ["World"] => array(5) {
//  ["Asia"] => array(1) {
//    ["Afghanistan"] => array(1) {
//      [0] => string(3) "..."
//    }
//  }
//  ["Africa"] => bool(true)
//  ["Antarctica"] => float(-25.2)
//  ["Europe"]=> object(stdClass)#298 (0) {}
//  ["North America"]=> []
//}
```

### Flatten

[](#flatten)

Flattens a tree to a map which keys are the materialized path of the node's keys:

```
use PFlorek\Elevator\Elevator;
use PFlorek\Elevator\ElevatorFactory;
use function \PFlorek\Elevator\array_flatten;

$elevated = [
    'World' => [
        'Asia' => [
            'Afghanistan' => [
                '...'
            ]
        ],
        'Africa' => true,
        'Antarctica' => -25.2,
        'Europe' => new \stdClass(),
        'North America' => [],
    ]
];

// object oriented
$factory = ElevatorFactory::getInstance();
$elevator = $factory->create();
$elevator->down($flattened);

// or functional
$flattened = array_flatten($elevated);

var_dump($flattened);

//returns array(5) {
//  ["World.Asia.Afghanistan.0"] => string(3) "..."
//  ["World.Africa"] => bool(true)
//  ["World.Antarctica"] => float(-25.2)
//  ["World.Europe"] => object(stdClass) (0) { }
//  ["World.North America"] => array(0) { }
//}
```

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

[](#installation)

Use [Composer](https://getcomposer.org) to install the package:

```
composer require pflorek/elevator
```

Authors
-------

[](#authors)

- [Patrick Florek](https://github.com/pflorek)

Contribute
----------

[](#contribute)

Contributions are always welcome!

- Report any bugs or issues on the [issue tracker](https://github.com/pflorek/php-elevator/issues).
- You can download the sources at the package's [Git repository](https://github.com/pflorek/php-elevator).

License
-------

[](#license)

All contents of this package are licensed under the [MIT license](LICENSE).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

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

Total

6

Last Release

3350d ago

Major Versions

1.0.2 → 2.0.02017-03-17

PHP version history (3 changes)1.0.0PHP &gt;=5.6

1.0.0-RC1PHP ^7.0

1.0.2PHP &gt;=5.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13916107?v=4)[Patrick Florek](/maintainers/pflorek)[@pflorek](https://github.com/pflorek)

---

Top Contributors

[![pflorek](https://avatars.githubusercontent.com/u/13916107?v=4)](https://github.com/pflorek "pflorek (35 commits)")

---

Tags

arraycomposerflattenmaterialized-pathsphptreearrayserializemaptreematerialized pathflatten

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pflorek-elevator/health.svg)

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

###  Alternatives

[cuyz/valinor

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

1.5k9.2M108](/packages/cuyz-valinor)[aimeos/map

Easy and elegant handling of PHP arrays as array-like collection objects similar to jQuery and Laravel Collections

4.2k412.9k11](/packages/aimeos-map)[chdemko/sorted-collections

Sorted Collections for PHP &gt;= 8.2

222.5M3](/packages/chdemko-sorted-collections)[sarhan/php-flatten

Flattens multidimensional arrays, traversables and vars into one dimensional array.

21177.7k1](/packages/sarhan-php-flatten)[graze/data-structure

Data collections and containers

12287.4k8](/packages/graze-data-structure)[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)

PHPackages © 2026

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