我正在尝试生成这样的面包屑
main>link1>link2>link3
main>link1>link2
main>link1
这就是我要去
function GenerateBreadcrumbHTML($nav) {
$html = '';
foreach ($nav as $page) {
$html .= '';
$html .= '<a href="' . $page['link'] . '">' . $page['name'] . '</a> >';
$html .= GenerateBreadcrumbHTML($page['sub']);
$html .= '</br>';
}
return $html;
}
但我得到的输出为:
main cat 1 >sub main of 1 >
sub main of 1 >
main cat 2 >sub main of 2 >
sub main of 2 >
main cat 3 >sub main of 3 >
sub main of 3 >
main cat 4 >sub main of 4 >sub cat of 11 >
sub main of 4 >
请解释我的逻辑,以便我能得到想要的结果。