Skip to content

Instantly share code, notes, and snippets.

View nurzaly's full-sized avatar

Nurzaly Abd Rahman nurzaly

View GitHub Profile
@nurzaly
nurzaly / build-tree.php
Created March 6, 2021 07:13 — forked from vyspiansky/build-tree.php
PHP: convert object / array to tree structure
<?php
/**
* The below functions take the single level array of items as an argument
* and turn it into a multidimensional array structure (tree),
* where each item has an array of sub-items.
*
* Each item should have at least an `id` and `parent_id`,
* where the `parent_id` is `0` if it's top level.
*
* Source: http://goo.gl/p2GybZ