这是我的代码,我需要你的帮助来理解它。
<?php $tree = array(
array(
'name' => 'Item-1',
'children' => array()),
array('name' => 'Item-2',
'children' => array(
array('name' => 'Item-2-1',
'children' => array()),
)),
array('name' => 'Item-3',
'children' => array(
array('name' => 'Item-3-1',
'children' => array()),
array('name' => 'Item-3-2',
'children' => array(
array('name' => 'Item-3-2-1',
'children' => array()),
array('name' => 'Item-3-2-2',
'children' => array()),
array('name' => 'Item-3-2-3',
'children' => array(
array('name' => 'Item-3-2-3-1',
'children' => array()),
)),
)),
)),
);
我需要的是一个递归函数,它将返回所有名称(名称)。例如:
Item-1
Item-2
Item-2-1
Item-3
Item-3-1
Item-3-2
...........
我的尝试,但它似乎对我不起作用
function tree($tree){
foreach ($tree as $key =>$value) {
foreach ($value as $key=>$value){
echo "$value<br>"; }
echo "<br>"; } }