Skip to content

Instantly share code, notes, and snippets.

View ydarwin's full-sized avatar
🎯
Focusing

Darwin Naranjo ydarwin

🎯
Focusing
View GitHub Profile
@ydarwin
ydarwin / build-tree.php
Created October 2, 2023 14:36 — 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