我已经坚持了两天了,我完全被困住了。谷歌和 SO 无法进一步帮助我,我忽略了一些东西....
这就是我要的
Home
Typography
404 Page not found
The company
The company/Team
The company/Team/Rick
The company/Team/Rick/Opleiding
The company/Team//Rob
The company/Office
The company/Office/Contact
The company/Office/Route
这是我的数组
Array
(
[0] => Array
(
[id] => 55
[parent_id] => 0
[title] => Home
[sub] => Array
(
)
)
[1] => Array
(
[id] => 27
[parent_id] => 0
[title] => Typography
[sub] => Array
(
)
)
[2] => Array
(
[id] => 56
[parent_id] => 0
[title] => 404 Page not found
[sub] => Array
(
)
)
[3] => Array
(
[id] => 68
[parent_id] => 0
[title] => The company
[sub] => Array
(
[0] => Array
(
[id] => 73
[parent_id] => 68
[title] => Team
[sub] => Array
(
[0] => Array
(
[id] => 74
[parent_id] => 73
[title] => Rick
[sub] => Array
(
[0] => Array
(
[id] => 79
[parent_id] => 74
[title] => Opleiding
[sub] => Array
(
)
)
)
)
[1] => Array
(
[id] => 75
[parent_id] => 73
[title] => Rob
[sub] => Array
(
)
)
)
)
[1] => Array
(
[id] => 76
[parent_id] => 68
[title] => Office
[sub] => Array
(
[0] => Array
(
[id] => 78
[parent_id] => 76
[title] => Contact
[sub] => Array
(
)
)
[1] => Array
(
[id] => 77
[parent_id] => 76
[title] => Route
[sub] => Array
(
)
)
)
)
)
)
)
这是我到目前为止所拥有的
public function BuildTitle($array, &$parents = null)
{
$html = '';
foreach($array as $page)
{
if($page['parent_id'] != 0)
{
$html .= $parents.'/'.$page['title'].'<br/>';
$parents = $parents.'/'.$page['title'];
}
else
{
$html .= $page['title'].'<br/>';
$parents = $page['title'];
}
$html .= $this->BuildTitle($page['sub'], $parents);
}
return $html;
}
这又回来了
Home
Typography
404 Page not found
The company
The company/Team
The company/Team/Rick
The company/Team/Rick/Opleiding
The company/Team/Rick/Opleiding/Rob
The company/Team/Rick/Opleiding/Rob/Office
The company/Team/Rick/Opleiding/Rob/Office/Contact
The company/Team/Rick/Opleiding/Rob/Office/Contact/Route
父/子关系是无限的。我在做什么错/错过了什么?提前致谢!