Skip to content

Instantly share code, notes, and snippets.

@kgundula
Created November 13, 2013 09:31
Show Gist options
  • Save kgundula/7446238 to your computer and use it in GitHub Desktop.
Save kgundula/7446238 to your computer and use it in GitHub Desktop.
Menu Tree Builder from an sql resultset.
/*
* This function can be use to build a menu tree.
*/
function buildMenuTree($menus, $parentId = 0) {
$branch = array();
foreach ($menus as $menu) {
if ($menu['parent_id'] == $parentId) {
$children = $this->buildMenuTree($menus, $menu['id']);
if ($children) {
$menu['child'] = $children;
}
$branch[] = $menu;
}
}
return $branch;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment