I have an array like so:
[0] => Array
(
[Project] => Array
(
[ExternalProjectID] => 53
[ProjectName] => Doon Creek
[Location] => Array
(
[Address] => 123 Fake Street
[City] => Toronto
[Province] => ON
[Latitude] => 43.0000
[Longitude] => -80.0000
)
[Website] => http://www.website.com/our-communities.php?newcommunity=53
[ContactInformation] => Array
(
[ContactPhone] => 555-5555
[ContactEmail] => email@email.com
[SalesOfficeAddress] => 123 Fake Street
[SalesOfficeCity] => Toronto
[SalesOfficeProvince] => ON
)
)
)
Now I am trying to covert this to XML exactly how this looks in the array, like Project should be a node with everything inside, Location should also be a node with everything inside the Location array inside that node, along with ContactInformation.
This is what I have:
$xml = new SimpleXMLElement();
$node = $xml->addChild('Projects');
array_to_xml($newArray, $node);
echo $xml->asXML();
die();
function array_to_xml($array, &$xml) {
foreach($array as $key => $value) {
if(is_array($value)) {
if(!is_numeric($key)){
$subnode = $xml->addChild("$key");
array_to_xml($value, $xml);
} else {
array_to_xml($value, $xml);
}
} else {
$xml->addChild("$key","$value");
}
}
}
but Project, Location and ContactInformation return as like so:
<Projects>
<Project />
<ExternalProjectID>53</ExternalProjectID>
<ProjectName>Doon Creek</ProjectName>
<Location />
<Address>123 Fake St.</Address>
<City>Toronto</City>
<Province>ON</Province>
<Latitude>43.0000</Latitude>
<Longitude>-80.000</Longitude>
<Website>http://www.website.com/our-communities.php?newcommunity=53</Website>
<ContactInformation />
<ContactPhone>555-5555</ContactPhone>
<ContactEmail>email@email.com</ContactEmail>
<SalesOfficeAddress>123 Fake Street</SalesOfficeAddress>
<SalesOfficeCity>Toronto</SalesOfficeCity>
<SalesOfficeProvince>ON</SalesOfficeProvince>
<Project />
</Projects>
My question is how do I fix my XML Output?