我想遍历这个数组并显示“评论”作为要点。
Array
(
[1] => Array
(
[id] => 1
[comment] => a
[parent_id] => 0
[children] => Array
(
[3] => Array
(
[id] => 3
[comment] => c
[parent_id] => 1
[depth] => 0
[child_count] => 0
[children] =>
)
[4] => Array
(
[id] => 4
[comment] => d
[parent_id] => 1
[depth] => 0
[child_count] => 0
[children] =>
)
)
[depth] => 1
[child_count] => 2
)
[2] => Array
(
[id] => 2
[comment] => b
[parent_id] => 0
[children] => Array
(
[5] => Array
(
[id] => 5
[comment] => e
[parent_id] => 2
[children] => Array
(
[7] => Array
(
[id] => 7
[comment] => g
[parent_id] => 5
[children] => Array
(
[8] => Array
(
[id] => 8
[comment] => h
[parent_id] => 7
[children] => Array
(
[9] => Array
(
[id] => 8
[comment] => h
[parent_id] => 8
[children] => Array
(
[10] => Array
(
[id] => 8
[comment] => h
[parent_id] => 9
[depth] => 0
[child_count] => 0
[children] =>
)
)
[depth] => 1
[child_count] => 1
)
)
[depth] => 2
[child_count] => 1
)
)
[depth] => 3
[child_count] => 1
)
)
[depth] => 4
[child_count] => 1
)
[6] => Array
(
[id] => 6
[comment] => f
[parent_id] => 2
[depth] => 0
[child_count] => 0
[children] =>
)
)
[depth] => 5
[child_count] => 2
)
)
你需要一点递归
function traverse_array($array)
{
echo '<ul>';
foreach($array as $element)
{
echo '<li>';
if(isset($element['comment']))
{
echo $element['comment'];
}
if(is_array($element['children']) && count($element['children']) > 0)
{
traverse_array($element['children']);
}
echo '</li>';
}
echo '</ul>';
}
traverse_array($the_big_array);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)