Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数组到XML在过程中间失败_Php_Xml_Simplexml - Fatal编程技术网

Php 数组到XML在过程中间失败

Php 数组到XML在过程中间失败,php,xml,simplexml,Php,Xml,Simplexml,正如您在下面所看到的,所有内容都与uid和pwd元素密切相关。突然用价值观俯冲某地。我是不是遗漏了什么 原始代码是 代码: $array = array('table'=>'users', 'operation'=>'insert', 'uid'=>'yoyo', 'pwd'=>'123'); $output = serialize($array); $xml = new SimpleXMLElement('<root/>'); array_walk_rec

正如您在下面所看到的,所有内容都与
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>
$array=array('table'=>'users','operation'=>'insert','uid'=>'yoyo','pwd'=>'123');
$output=序列化($array);
$xml=新的SimpleXMLElement(“”);
数组_walk_递归(非序列化($output),数组($xml,'addChild');
echo$xml->asXML();
结果:

$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>

桌子
活动
液体
pwd

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

换线

$output = serialize($array);