我正在尝试显示带有 html 标记 ul 和 li 的 html 树。我正在使用递归方法获取信息并相应地显示:
Array
(
[0] => Array
(
[id] => 1
)
[1] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 2
)
[1] => Array
(
[0] => Array
(
[0] => Array
(
[id] => 4
)
[1] => Array
(
[0] => Array
(
[id] => 9
)
[1] => Array
(
[id] => 10
)
[2] => Array
(
[id] => 11
)
)
)
[1] => Array
(
[id] => 5
)
)
)
[1] => Array
(
[0] => Array
(
[id] => 3
)
[1] => Array
(
[0] => Array
(
[id] => 6
)
[1] => Array
(
[id] => 7
)
[2] => Array
(
[id] => 8
)
)
)
)
)
这是我的数组,我以递归方法遍历以使用 ul 和 li 标签正确识别它。但我似乎无法让它完美地工作:P 关于我做错了什么的任何想法?这是我使用的方法:
public function test($data){
echo '<ul>';
foreach ($data as $row) {
if(isset($row['id'])){
echo '<li>' . $row['id'] . '</li>';
}else{
$this->test($row);
}
}
echo '</ul>';
}