php array itetive visual parent>儿童 [英] php array iteration visually parent > child
问题描述
设法用childs创建数组树。看起来像这样。
managed to create array tree with childs. Looks like this.
想要尝试打印它具有相同的水平。
Want to try printing it out with same levels.
<ul>
<li>cat1</li>
<ul><li>sub-cat</li>
<ul><li>subsub-cat</li>
<ul><li>subsubsub-cat</li>
<ul><li>subsubsubsub-cat</li></ul>
<li>subcub-cat2</li>
<ul></ul></ul></ul></ul>
<li>cat2</li>
</ul>
需要使用迭代角度。至少指向正确的方向。
Need to use iterative angle. At least point me to to the right direction.
它不一定是UL LI,可以是 - 或某种类似,只需要使用迭代方法打印出来。
It doesn't have to be with UL LI, can be with -- -- or some sort similar, just need to print it out using iterative methods.
推荐答案
这不是确切的解决方案,但你可以使用这样的东西
It is not the exact solution but you can use something like this
foreach( $array as $item ){
echo $item['id'].'<br>';
while(isset($item['child'])){
$item = $item['child'];
echo $item['id'].'<br>';
}
}
这是我生成的代码示例
http://sandbox.onlinephpfunctions.com/code/068f8b2d79cb5e210a6ee4c8e14c1a8649ab0dea
here is the code sample that i generated http://sandbox.onlinephpfunctions.com/code/068f8b2d79cb5e210a6ee4c8e14c1a8649ab0dea
这篇关于php array itetive visual parent>儿童的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!