一开始写的循环加判断乱糟的。
后来发现用simplexml_load_file()处理很好用.并写了个函数来做数组重组处理赋值.重组一个新的数组.

function shownode($node,$i=0){
	foreach($node  as $key => $value){
		global ${$key};
		if($key=="items")${$key}=count($value);
		${$key}[$i]=$value;
		shownode($value,$i);
	$i++;
	}
}
function arradd($t){
$tv=implode(',', $t);
$t=explode(',',$tv);
if(count($t)==1){$t=$tv;}
return $t;
}
if($_POST['OrderDetail']=="")exit("没有数据");
$load_file="../caches/caches.xml";//缓存XML文件
callback($load_file,$_POST['OrderDetail']);
$order=simplexml_load_file($load_file);//var_dump($order);
shownode($order);//将所有数组赋值给自己的键,键为变量名称.使用了动态变量.详细看上面函数
//遍历重组数组.
$order_id=arradd($order_id);
$customer_id=arradd($customer_id);
$order_create_time=arradd($order_create_time);
$customer_lastname=arradd($customer_lastname);
$customer_firstname=arradd($customer_firstname);
$order_id;//XML有一个值的
$firstname[0];//xml有2个值的
$firstname[1];

简单的解决数据接受.

» 版权所有:YaoLei's Blog » PHP 接收XML 处理
» 本文链接:https://www.yaolei.info/archives/102