Skip to content

Instantly share code, notes, and snippets.

@taion809
Created September 10, 2013 14:29
Show Gist options
  • Save taion809/6510212 to your computer and use it in GitHub Desktop.
Save taion809/6510212 to your computer and use it in GitHub Desktop.
PHP Nested set to multidimensional array
private function _formatTreeIntoArray(&$tree, $current_depth = 0)
{
$formattedTree = array();
while($leaf = current($tree))
{
if($leaf->DEPTH > $current_depth)
{
$formattedTree[] = $this->_formatTreeIntoArray($tree, $leaf->DEPTH);
}
elseif($leaf->DEPTH < $current_depth)
{
return $formattedTree;
}
else
{
$formattedTree[] = $leaf;
next($tree);
}
}
return $formattedTree;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment