Skip to content

Instantly share code, notes, and snippets.

View ubermaniac's full-sized avatar

Joseph Woodruff ubermaniac

  • SOCi, Inc.
  • Eagle Mountain, Utah
View GitHub Profile
@ubermaniac
ubermaniac / covertToHierarchy.php
Last active April 21, 2021 14:28
Convert a DB result of parent/child items into a hierarchical array
<?php
// -- Only one caveat : The results must be ordered so that an item's parent will be processed first.
// -- Simulate a DB result
$results = array();
$results[] = array('id' => 'a', 'parent' => '', 'name' => 'Johnny');
$results[] = array('id' => 'b', 'parent' => 'a', 'name' => 'Bobby');
$results[] = array('id' => 'c', 'parent' => 'b', 'name' => 'Marky');
$results[] = array('id' => 'd', 'parent' => 'a', 'name' => 'Ricky');

Keybase proof

I hereby claim:

  • I am ubermaniac on github.
  • I am ubermaniac (https://keybase.io/ubermaniac) on keybase.
  • I have a public key ASAt3WuYE9Qx-BzMLvJYjNojuJWmUgHmyqTE42x5KyhXJwo

To claim this, I am signing this object: