我有一个 php 数组在下面,
$two_dimention = array(
array("id"=>4, "name" => "Home", "parent" => 0, "depth" => 0),
array("id"=>5, "name" => "Menu 1", "parent" => 0, "depth" => 0),
array("id"=>6, "name" => "Menu 2", "parent" => 0, "depth" => 0),
array("id"=>8, "name" => "Menu 2.1", "parent" => 6, "depth" => 1),
array("id"=>10, "name" => "Menu 2.1.1", "parent" => 8, "depth" => 2),
array("id"=>11, "name" => "Menu 2.1.2", "parent" => 8, "depth" => 2),
array("id"=>9, "name" => "Menu 2.2", "parent" => 6, "depth" => 1),
array("id"=>7, "name" => "Menu 3", "parent" => 0, "depth" => 0),
array("id"=>18, "name" => "Menu 3.1", "parent" => 7, "depth" => 1),
);
根据这个 $two_dimention 数组,它将创建 HTML 中的多维订单列表,如下所示,
<ul>
<li>Home</li>
<li>Menu 1</li>
<li>Menu 2
<ul>
<li>Menu 2.1
<ul>
<li>Menu 2.1.1</li>
<li>Menu 2.1.2</li>
</ul>
</li>
<li>Menu 2.2</li>
</ul>
</li>
<li>Menu 3
<ul>
<li>Menu 3.1</li>
</ul>
</li>
</ul>
我怎样才能通过 PHP for/foreach 循环来做到这一点?
慕森卡