I need help with this issue, it seems I can't get targetCurrency out of the SimpleXMLElement Object
$xmlString = <<<XML
<channel>
<title>XML ~~ Exchange Rates ~~</title>
<language>en</language>
<item>
<baseCurrency>USD</baseCurrency>
<targetCurrency>EUR</targetCurrency>
<targetName>Euro</targetName>
<exchangeRate>0.90900497</exchangeRate>
</item>
</channel>
XML;
$xml = simplexml_load_string($xmlString);
foreach($xml->item as $rate){
$rate = (string) $rate->exchangeRate;
$curr_code = (string) $rate->targetCurrency;
$money[] = array('rate' => $rate, 'curr_code' => $curr_code);
}
print_r($money);
This outputs:
Array
(
[0] => Array
(
[rate] => 0.90947603
[curr_code] =>
)
)
[curr_code] should output 'EUR'.
How can I fix it?