- var_dump: documentation ( source)
- simplexml_load_string: documentation ( source)
- print_r: documentation ( source)
<?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);