源数组:$attributes=array('Users'=>array('Name'=>'Name',),'Address'=>'Address','Tags'=>array(0=>array('Key'=>'Key','Value'=>'Value',),1=>array('Key'=>'Key',),2=>array()),);希望转换为如下数组:$result=array('Users_Name'=>'Name','Address'=>'Address','Tags_0_Key'=>'Key','Tags_0_Value'=>'Value','Tags_1_Key'=>'Key',//'Tags_2'=>'',);递归方式尝试了半天,依然没有解决,如何转换呢?
2 回答
青春有我
TA贡献1784条经验 获得超8个赞
functiont($parent_key,$parent_array,&$data){foreach($parent_arrayas$k=>$v){if(is_array($v)){t("${parent_key}_${k}",$v,$data);}else{$data[trim("${parent_key}_${k}",'_')]=$v;}}}$data=array();$attributes=array('Users'=>array('Name'=>'Name',),'Address'=>'Address','Tags'=>array(0=>array('Key'=>'Key','Value'=>'Value',),1=>array('Key'=>'Key',),2=>array()),);t('',$attributes,$data);print_r($data);
添加回答
举报
0/150
提交
取消