Support the ongoing development of Laravel.io →
posted 6 years ago
Blade
Last updated 2 years ago.
0

1st option: get the correct structure specifically in maps and name the arrays.

2nd option: in the event that you can't change the $maps arrays got, at that point you can adjust the head level by adding check to it:

$maps = [ 0 => [ "id" => 1, "name" => "Leeuwarden", "address" => "Leeuwarden", "lat" => 53.20132, "lng" => 5.80005, ], 1 => [ "id" => 2, "name" => "Assen", "address" => "Assen", "lat" => 52.99275, "lng" => 6.56423, ] ];

function to_xml(\SimpleXMLElement $object, array $data, $level = 0) { foreach ($data as $key => $value) { if (is_array($value)) { $new_object = $object->addChild(($level == 0) ? 'marker' : $key); to_xml($new_object, $value, $level + 1); } else { $object->addChild($key, $value); } } }

$xml = new \SimpleXMLElement('<rootTag/>'); to_xml($xml, $maps);

header('Content-type: text/xml'); echo $xml->asXML();

By:Xtreem Solution

Top laravel web developers

Dedicated PHP Developer

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Martin sx000 Joined 26 Sep 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.