Using SimpleXML
for # 1 (as in How to convert an array to SimpleXML )
<?php
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($test_array, array ($xml, 'addChild'));
print $xml->asXML("file.xml");
for # 2
$xml_data_as_object = simplexml_load_file("file.xml")
returns a representation of an XML data object.
convert an object to an array using:
$xml_data_as_array = array();
foreach ($xml_data->root as $children) {
$xml_data_as_array[] = array(
"name" => $children->name,
"surname" => $children->surname,
"country" => $children->country,
"date" => $children->date
);
}
source
share