$arr=array( '10'=>array( '12'=>0 ), '15'=>array( '30'=>array( '35'=>0 ), '31'=>array( '40'=>0 ) ))
$a[]='10,12';$a[]='15,30,35';$a[]='15,31,40';
$arr=array('10'=>array('12'=>0),'15'=>array('30'=>array('35'=>0),'31'=>array('40'=>0))); $a=array(); foreach ($arr as $k=>$v){ $a[$k][]=$k; if(is_array($v)){ foreach ($v as $kk=>$vv){ $a[$k][]=$kk; } } } var_dump($a);
$arr=array('10'=>array('12'=>0),'15'=>array('30'=>array('35'=>0),'31'=>array('40'=>0),'33'=>array('42'=>0))); $a=array(); $i=0; foreach ($arr as $k=>$v){ $a[$i][]=$k; if(is_array($v)){ foreach ($v as $kk=>$vv){ $a[$i][]=$kk; if(is_array($vv)){ foreach ($vv as $kkk=>$vvv){ $j=0; if($j==0){ unset($a[$i]); $a[$i.'-'.$i][]=$k; $a[$i.'-'.$i][]=$kk; $a[$i.'-'.$i][]=$kkk; }else{ $a[$i][]=$kkk; } } } $i++; } } $i++; } var_dump($a);
最后是这样$arr=array('10'=>array('12'=>0),'15'=>array('30'=>array('35'=>0),'31'=>array('40'=>0),'33'=>array('42'=>0))); $a=array(); $i=0; foreach ($arr as $k=>$v){ $a[$i][]=$k; if(is_array($v)){ foreach ($v as $kk=>$vv){ $a[$i][]=$kk; if(is_array($vv)){ foreach ($vv as $kkk=>$vvv){ unset($a[$i]); $a[$i.'-'.$i][]=$k; $a[$i.'-'.$i][]=$kk; $a[$i.'-'.$i][]=$kkk; } } $i++; } } } var_dump(array_values($a));
$arr=array( '10'=>array( '12'=>0 ), '15'=>array( '30'=>array( '35'=>0 ), '31'=>array( '40'=>0 ) ));print_r(foo($arr));function foo($ar) { $res = array(); foreach($ar as $k=>$v) { if(is_array($v)) { foreach(foo($v) as $r) $res[] = "$k,$r"; }else $res[] = $k; } return $res;}
Array( [0] => 10,12 [1] => 15,30,35 [2] => 15,31,40)