数组到xml在处理过程中失败


array to xml fails in the middle of process

正如您在下面看到的,uidpwd元素的一切都很顺利。突然拥有价值的地方。我是不是遗漏了什么?

原始代码来自这里。

代码:

$array = array('table'=>'users', 'operation'=>'insert', 'uid'=>'yoyo', 'pwd'=>'123');
$output = serialize($array);
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive(unserialize($output), array($xml, 'addChild'));
echo $xml->asXML();

结果:

<?xml version="1.0"?>
<root>
<users>table</users>
<insert>operation</insert>
<yoyo>uid</yoyo>
<123>pwd</123>
</root>

根据您的需要,您必须翻转您的阵列,所以请尝试,

更改线路

$output = serialize($array); 

带有

$output = serialize(array_flip($array));