php简单的数组递归
<?php
$arr = array(
'zz'=>1,
'aa' => array(
'bb' => array(
'id'=>5,
'grade'=>5,
'a'=>111
),
'cc' => array(
array(
"name"=>'some',
"a"=>999
)
),
'dd' => array(
'ctime'=>1001
)
),
'ee' => array(
'ff' =>array(
'age'=> 25,
'sex'=>1
)
)
);
function ToUrlParams($arr,&$data=array()){
global $str;
ksort($arr);
if(!is_array($arr)){
echo $arr."不是数组";
}else{
foreach($arr as $k=>$v){
if(is_array($v)){
ksort($v);
ToUrlParams($v);
}else{
$str .= $k.'='.$v.'&';
}
}
}
return substr($str,0,strlen($str)-1);
}
$str = ToUrlParams($arr);
echo $str;
输出:
a=111&grade=5&id=5&a=999&name=some&ctime=1001&age=25&sex=1&zz=1
?>