正如您在下面看到的,uid
和pwd
元素的一切都很顺利。突然拥有价值的地方。我是不是遗漏了什么?
原始代码来自这里。
代码:
$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));