array(
array(
"id" => 1,
"title" => "a",
"cid" => 0,
"child" => ''
),
array(
"id" => 2,
"title" => "a",
"cid" => 0,
"child" => array(
array(
"id" => 7,
"title" => "b",
"cid" => 2,
"child" =>''
),
array(
"id" => 8,
"title" => "b",
"cid" => 2,
"child" =>array(
array(
"id" => 9,
"title" => "c",
"cid" => 8,
"child" => ''
)
)
),
)
),
array(
"id" => 3,
"title" => "a",
"cid" => 0,
"child" => ''
),
);
这个数组是我手打的,应该是对的。 然后把这个数组在视图文件中变成
<ul>
<li>a</li>
<li>a
<ul>
<li>b</li>
<li>b
<ul>
<li>c</li>
</ul>
</li>
</ul>
</li>
<li>a</li>
</ul>
aa($array);
function aa($array)
{
if (empty($array)) {
return ;
}
echo '<ul>';
foreach ($array as $v) {
echo '<li>'.$v['title'];
aa($v['child']);
echo '</li>';
}
echo '</ul>';
}
|