我有一系列菜单。它有标题,深度,mlid(菜单ID)和plid(父ID)。我想创建像这样的
的html结构 <li class="has-children">
<a href="#?p=409">Accessories</a>
<ul class="is-hidden">
<li class="go-back"><a href="#0">Clothing</a></li>
<li class="see-all"><a href="#?p=409">All Accessories</a></li>
<li class="has-children">
<a href="#0">Beanies</a>
<ul class="is-hidden">
<li class="go-back"><a href="#0">Accessories</a></li>
<li class="see-all"><a href="#?p=409">All Benies</a></li>
<li><a href="#?p=409">Caps & Hats</a></li>
<li><a href="#?p=409">Gifts</a></li>
<li><a href="#?p=409">Scarves & Snoods</a></li>
</ul>
</li>
<li><a href="#?p=409">Glasses</a></li>
<li><a href="#?p=409">Gloves</a></li>
<li><a href="#?p=409">Jewellery</a></li>
<li><a href="#?p=409">Scarves</a></li>
<li><a href="#?p=409">Wallets</a></li>
<li><a href="#?p=409">Watches</a></li>
</ul>
</li>
我在cms中的菜单就像这个
目前在cms。就像这样 $菜单
Array
(
[0] => Array
(
[name] => Accessories
[depth] => 1
[mlid] => 353
[plid] => 0
)
[1] => Array
(
[name] => Beanies
[depth] => 2
[mlid] => 354
[plid] => 353
)
[2] => Array
(
[name] => Gifts
[depth] => 3
[mlid] => 355
[plid] => 354
)
[3] => Array
(
[name] => Caps
[depth] => 3
[mlid] => 357
[plid] => 354
)
[4] => Array
(
[name] => Scarves
[depth] => 3
[mlid] => 356
[plid] => 354
)
[5] => Array
(
[name] => Glasses
[depth] => 2
[mlid] => 358
[plid] => 353
)
)
我失去了如何编写代码,使得这个菜单可以根据树的层次结构将这个菜单定向到html结构或像数组这样的子代(所以我可以从那里开始制作html)。谢谢。
答案 0 :(得分:3)
使用foreach循环并在其中编写html代码。
foreach ($ menu as $ v => $ r)
{
<"Your html code here">
}
希望这足够了。