PHPackages                             waughj/flat-to-hierarchy-sorter - 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. waughj/flat-to-hierarchy-sorter

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

waughj/flat-to-hierarchy-sorter
===============================

Sorts flat list of nodes into hierarchy.

v0.1.0(6y ago)0691AGPL-3.0-or-laterPHPPHP &gt;=7.2

Since Oct 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/waughjai/flat-to-hierarchy-sorter)[ Packagist](https://packagist.org/packages/waughj/flat-to-hierarchy-sorter)[ RSS](/packages/waughj-flat-to-hierarchy-sorter/feed)WikiDiscussions master Synced yesterday

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

Flat to Hierarchy Sorter
========================

[](#flat-to-hierarchy-sorter)

Sorts flat list of nodes with IDs and parent IDs into layered list of nodes with IDs and lists of children to make iteration easier.

Example
-------

[](#example)

```
use WaughJ\FlatToHierarchySorter\FlatToHierarchySorter;
use WaughJ\FlatToHierarchySorter\HierarchicalNode;

$old_list =
[
    new HierarchicalNode( 1, 0 ),
    new HierarchicalNode( 2, 1 ),
    new HierarchicalNode( 3, 1 ),
    new HierarchicalNode( 4, 2 )
];
$sorted_list = FlatToHierarchySorter::sort( $old_list );

```

will return to equivalent of:

```
new HierarchicalNode
(
    1,
    0,
    [
        new HierarchicalNode( 2, 1, [ new HierarchicalNode( 4, 2 ) ] ),
        new HierarchicalNode( 3, 1 )
    ]
);

```

Changelog
---------

[](#changelog)

### 0.1.0

[](#010)

- Initial release

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

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

Unknown

Total

1

Last Release

2398d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/11161078?v=4)[waughj](/maintainers/waughj)[@waughj](https://github.com/waughj)

---

Tags

converterhierarchysorterOrganizer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/waughj-flat-to-hierarchy-sorter/health.svg)

```
[![Health](https://phpackages.com/badges/waughj-flat-to-hierarchy-sorter/health.svg)](https://phpackages.com/packages/waughj-flat-to-hierarchy-sorter)
```

###  Alternatives

[mark-gerarts/auto-mapper-plus

An AutoMapper for PHP

5623.2M21](/packages/mark-gerarts-auto-mapper-plus)[iamcal/php-emoji

This is a PHP library for dealing with Emoji, allowing you to convert between various native formats and displaying them using HTML.

1.3k481.1k](/packages/iamcal-php-emoji)[matthiasmullie/path-converter

Relative path converter

10229.6M7](/packages/matthiasmullie-path-converter)[ncjoes/office-converter

PHP Wrapper for LibreOffice

2431.2M4](/packages/ncjoes-office-converter)[kartik-v/yii2-tree-manager

An enhanced tree management module with tree node selection and manipulation using nested sets.

156529.0k15](/packages/kartik-v-yii2-tree-manager)[henck/rtf-to-html

RTF to HTML converter in PHP

108785.6k1](/packages/henck-rtf-to-html)

PHPackages © 2026

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