我有一个需要转换为XML格式的数组。
[name] => ABC
[email] => email@email.com
[phones] => Array
(
[phone] => Array
(
[0] => Array
(
[mobile] => 91454599193
[land] => 9999999
)
[1] => Array
(
[mobile] => 54520199193
[land] => 9999999
)
[2] => Array
(
[mobile] => 90424249194
[land] => 5555555
)
[3] => Array
(
[mobile] => 44224199195
[land] => 8888888
)
)
)
我希望您能按照以下格式进行排版:
我想让这个内容以以下格式呈现
<name>ABC</name>
<email>email@email.com</email>
<phones>
<phone>
<mobile>545450199193</mobile>
<land>9999999</land>
</phone>
<phone>
<mobile>575199193</mobile>
<land>9999999</land>
</phone>
</phones>
请帮我忙...
这是我的函数,我是这样写的。我面临的问题是:必须在具有数字的索引中显示XML节点中的文本。例如:在电话数组下面,有索引[0],[1]。我希望在我的XML页面中将[0],[1]替换为<phone>
。
function array_to_xml($value, &$xml_student_info) {
foreach($value as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml_student_info->addChild("$key");
array_to_xml($value, $subnode);
}
else{
array_to_xml($value, $xml_student_info);
}
}
else {
$xml_student_info->addChild("$key","$value");
}
}
}