"haha2",id=2,pid=0), array("name"=>"haha2,1",id=3,pid=2), array("name"=>"haha2,">
时间:2021-07-01 10:21:17 帮助过:23人阅读
问题解决了
arrto2($x,$v["@attributes"]['id']);就ok了
加上meta charset就不会乱码了。
hh.xml
';print_r(arrto2($arr['hh']));function arrto2($arr,$pid=0){ static $i=1; static $data=array(); foreach($arr as $v){ if(is_array($v)){ foreach($v as $z => $x){ if($z==="@attributes"){ $v["@attributes"]['id']=$i; $v["@attributes"]['pid']=$pid; $data[$i]=$v["@attributes"]; }else{ arrto2($x,$i); } $i++; } } } return $data;}?>
Array( [1] => Array ( [name] => haha1哈哈 [id] => 1 [pid] => 0 ) [2] => Array ( [name] => haha2哈哈 [id] => 2 [pid] => 0 ) [3] => Array ( [name] => haha2.1哈哈 [id] => 3 [pid] => 3 ) [4] => Array ( [name] => haha2.2哈哈 [id] => 4 [pid] => 3 ) [6] => Array ( [name] => haha3哈哈 [id] => 6 [pid] => 0 ) [7] => Array ( [name] => haha3.1哈哈 [id] => 7 [pid] => 7 ) [8] => Array ( [name] => haha3.2哈哈 [id] => 8 [pid] => 7 ))