3v4l.org

run code in 300+ PHP versions simultaneously
<?php $xml_string = '<?xml version="1.0"?> <result> <code> <name>Warszawa</name> <lat>52.25</lat> <lng>21.0</lng> <otherDetails>some Warsaw info here</otherDetails> </code> <code> <name>Somewhere Else</name> <lat>42</lat> <lng>99</lng> <otherDetails>some info about somewhere else here</otherDetails> </code> </result> '; $xml = simplexml_load_string($xml_string); echo "\n\n\$xml:\n\n"; print_r($xml); $codeZero = null; foreach ($xml->code->children() as $child) { $codeZero = $child; } echo "\n\n\$codeZero:\n\n"; var_dump($codeZero); $lat = null; foreach ($codeZero->children() as $child) { if (isset($child->lat)) { $lat = $child->lat; } } echo "\n\n\$lat:\n\n"; var_dump($lat);

preferences:
63.54 ms | 406 KiB | 5 Q