php简单的数组递归
$arr = array(
'aa' => array(
'bb' => array(
'id'=>5,
'grade'=>5
),
'cc' => array(
"name"=>'some'
),
'dd' => array(
'ctime'=>1001
)
),
'ee' => array(
'ff' =>array(
'age'=> 25,
'sex'=>1
)
)
);
function a($arr){
if(!is_array($arr)){
echo $arr."\n";
}else
foreach($arr as $k=>$v){
if(is_array($v)){
echo "键是$k"."\n";
echo a($v)."\n";
}else{
echo "键是$k"."\n";
echo $v."\n";
}
}
}
a($arr);
结果
键是aa
键是bb
键是id
5
键是grade
5
键是cc
键是name
some
键是dd
键是ctime
1001
键是ee
键是ff
键是age
25
键是sex
1