我很难掌握创建类别树的概念。这是标准:
- 创建一个无限深度的父/子 HTML 无序列表
- 删除所有 status = 0 的项目和任何孩子
- 创建 URL,例如 /clothes/jeans
- 可选:生成面包屑
我能找到的最接近的解决方案让我更加困惑,因为我无法让它们工作:
这是我的数组:
Array
(
[0] => Array
(
[id] => 1
[parent] => 0
[status] => 2
[slug] => clothes
[title] => Clothes
)
[1] => Array
(
[id] => 2
[parent] => 1
[status] => 2
[slug] => jeans
[title] => Jeans
)
[2] => Array
(
[id] => 3
[parent] => 1
[status] => 2
[slug] => dresses
[title] => Dresses
)
[3] => Array
(
[id] => 4
[parent] => 0
[status] => 2
[slug] => accessories
[title] => Accessories
)
[4] => Array
(
[id] => 5
[parent] => 4
[status] => 2
[slug] => bags
[title] => Bags
)
[5] => Array
(
[id] => 6
[parent] => 4
[status] => 2
[slug] => watches
[title] => Watches
)
[6] => Array
(
[id] => 7
[parent] => 6
[status] => 2
[slug] => rolex
[title] => Rolex
)
)
这是我想要的无序列表:
<ul>
<li><a href="/clothes">Clothes</a>
<ul>
<li>
<a href="/clothes/jeans">Clothes</a>
</li>
<li>
<a href="/clothes/dresses">Clothes</a>
</li>
</ul>
</li>
<li><a href="/accessories">Accessories</a>
<ul>
<li>
<a href="/accessories/bags">Bags</a>
</li>
<li>
<a href="/accessories/watches">Watches</a>
<ul>
<li>
<a href="/accessories/watches/rolex">Rolex</a>
</li>
</ul>
</li>
</ul>
</li>
</ul>