递归加入一个符号参数,如"空格",递归列表时把符号多连接上一倍,再输出
<?php$arr = array(
0 => array(
'name'=>'first',
'_child'=>array(
0 => array(
'name'=>'second',
'_child'=>array(
0 => array(
'name'=>'three',
'_child'=>array()
),
1 => array(
'name'=>'three',
'_child'=>array()
),
2 => array(
'name'=>'three',
'_child'=>array()
),
)
),
1 => array(
'name'=>'second',
'_child'=>array(
0 => array(
'name'=>'three',
'_child'=>array()
),
1 => array(
'name'=>'three',
'_child'=>array()
),
2 => array(
'name'=>'three',
'_child'=>array()
),
)
),
),
)
)
function echoData($arr,$str){
$str .= '&nbsp'
foreach ($arr as $k => $v) {
echo $str.$v['name'].'<br>'
if(count($v['_child'])){
echoData($v['_child'],$str)
}
}
}
echoData($arr,'')
?>
<?phpfunction fun($max, $n, $p=0){
if($p == pow($max, $n)){
exit
}
for($i = 0$i <$max$i++){
//do some thing
$p = $p +1
fun($max,$n,$p)
}
}
echo fun(3,3)
?>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)