【发布时间】:2011-06-10 19:09:30
【问题描述】:
我有一个多维数组,我试图找出如何简单地“回显”数组的元素。数组的深度是未知的,所以它可以嵌套很深。
对于下面的数组,正确的回显顺序是:
This is a parent comment
This is a child comment
This is the 2nd child comment
This is another parent comment
这就是我说的数组:
Array
(
[0] => Array
(
[comment_id] => 1
[comment_content] => This is a parent comment
[child] => Array
(
[0] => Array
(
[comment_id] => 3
[comment_content] => This is a child comment
[child] => Array
(
[0] => Array
(
[comment_id] => 4
[comment_content] => This is the 2nd child comment
[child] => Array
(
)
)
)
)
)
)
[1] => Array
(
[comment_id] => 2
[comment_content] => This is another parent comment
[child] => Array
(
)
)
)
【问题讨论】:
-
这将取决于您希望它被回显的顺序:广度优先还是深度优先? --开个玩笑,你已经包含了你想要的顺序
-
您是想回显这个以显示给用户还是为了开发检查/调试数组的内容?
标签: php arrays multidimensional-array nested