我正在使用递归函数在树中转换我的菜单。我从数据库中得到的数组是:
array (
[0] => stdClass Object (
[nav_group_id] => 1
[entity_id] => 1
[parent] => 0
[name] => Meter Reading
[link] => # )
[1] => stdClass Object (
[nav_group_id] => 1
[entity_id] => 2
[parent] => 0
[name] => Parameterization
[link] => # )
[2] => stdClass Object (
[nav_group_id] => 1
[entity_id] => 3
[parent] => 0
[name] => View Reports
[link] => # )
[3] => stdClass Object (
[nav_group_id] => 1
[entity_id] => 4
[parent] => 0
[name] => Management & Control
[link] => # )
[4] => stdClass Object (
[nav_group_id] => 1
[entity_id] => 5
[parent] => 1
[name] => Billing Data
[link] => # )
[5] => stdClass Object (
[nav_group_id] => 1
[entity_id] => 6
[parent] => 1
[name] => MDI Billing Data
[link] => # )
我通过将上述数组传递给该函数来调用递归函数:
$this->parseAndPrintTree('0',$navigation_all);
//die(); (issue here)
现在,如果我die();
在此功能之后使用它会显示正确的菜单,并且如果不使用die();
页面将无法加载并给出此错误:
内容编码错误您尝试查看的页面无法显示,因为它使用了无效或不受支持的压缩形式。”
...并且没有显示输出。这是我的递归函数:
function parseAndPrintTree($root, $tree)
{
$return = array();
if(!is_null($tree) && count($tree) > 0)
{
echo '<ul>';
foreach($tree as $child => $parent)
{
if($parent->parent == $root)
{
unset($tree[$child]);
echo '<li>'.$parent->name;
$this->parseAndPrintTree($parent->entity_id, $tree);
echo '</li>';
}
}
echo '</ul>';
}
}