我有一个数组title
and children
index.
title
始终不为空。children
是一个数组,空或非空。
Any children
have title
and children
等等。
$myArray = [
0 => [
'title' => 'N1',
'children' =>
[
0 =>
[
'title' => 'N11',
'children' =>
[
0 =>
[
'title' => 'N111',
'children' => [],
],
],
],
],
],
1 =>
[
'title' => 'N2',
'children' =>
[
0 =>
[
'title' => 'N21',
'children' =>
[],
],
],
],
];
现在,我想用这个数组创建一个下拉菜单。
我在创建无序列表时遇到问题(ul
, li
)来自这个数组。
我希望我的结果是这样的:
<ul>
<li>N1
<ul>
<li>N11
<ul>
<li>N111</li>
</ul>
</li>
</ul>
</li>
<li>N2
<ul>
<li>N21</li>
</ul>
</li>
</ul>