PHPackages                             ashleydawson/canonically-flatten-tree - 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. ashleydawson/canonically-flatten-tree

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

ashleydawson/canonically-flatten-tree
=====================================

Pure function to flatten a tree (n-dimensional array) into a canonicalised list array

1.0.3(1mo ago)03.3kproprietaryPHPPHP ^7.1|^8.2

Since Apr 7Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/AshleyDawson/CanonicallyFlattenTree)[ Packagist](https://packagist.org/packages/ashleydawson/canonically-flatten-tree)[ RSS](/packages/ashleydawson-canonically-flatten-tree/feed)WikiDiscussions master Synced 3w ago

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

Canonically Flatten Tree
========================

[](#canonically-flatten-tree)

[![Build Status](https://camo.githubusercontent.com/0e6d13aac25f1494fd91cc970fda1988f32458b367d9a7c3752c1477a8285c08/68747470733a2f2f7472617669732d63692e6f72672f4173686c6579446177736f6e2f43616e6f6e6963616c6c79466c617474656e547265652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/AshleyDawson/CanonicallyFlattenTree)

Pure PHP function to flatten an n-dimensional tree of scalars (represented as an array) into a single dimension list (also represented as an array).

TODO
----

[](#todo)

- Benchmark various flattening algorithms, including `\RecursiveArrayIterator`, etc.
- Technically I think it's a nested set we're operating on (sort of), so in v2 I'd propose changing the terminology to suit

Requirements
------------

[](#requirements)

This function requires PHP &gt;= 7.1

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

[](#installation)

Installation via [Composer](https://getcomposer.org/):

```
$ composer req ashleydawson/canonically-flatten-tree
```

Usage
-----

[](#usage)

Basic usage of the function is as follows:

```
