我在 PHP 中有一个关联数组。这是代码:
$result = mysql_query("SELECT * FROM `tb_menu` ORDER BY id ASC");
$menu = array();
$menu_index = array();
while($row = mysql_fetch_assoc($result)){
if($row['par'] == 0) {
$menu[] = $row;
$menu[sizeof($menu)-1]['child'] = array();
$menu_index[$row['id']] = &$menu[sizeof($menu)-1];
} else {
$menu_index[$row['par']]['child'][] = $row;
$menu_index[$row['id']] = &$menu_index[$row['par']]['child'][sizeof($menu_index[$row['par']]['child'])-1];
}
}
/*print ( '<pre>' ) ;
print_r ( $menu ) ;
print ( '</pre>' ) ; exit();*/
$smarty->assign('menu', $menu);
我无法让它在 smarty 上运行,因为我是它的初学者。请帮我制作这样的多级菜单
<ul>
<li><a href="">first level</a>
<ul>
<li><a href="">second level</a></li>
......................................
<ul>
<li><a href="">N-level</a></li>
<ul>
</ul>
</li>
</ul>
</li>
谢谢