I have below out using print_r();
how can i display individual like i want to display
[currency] => USD
[rate] => 1.3000
how to use foreach
Thanks
$xml = simplexml_load_file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
echo $xml->getName() . "<br />";
foreach($xml->children() as $child)
{
echo $child->getName()->currency . ": " . $child . "<br />";
echo '<pre>';
print_r($child);
echo '</pre>';
}
output
SimpleXMLElement Object
(
[Cube] => SimpleXMLElement Object
(
[@attributes] => Array
(
[time] => 2010-07-16
)
[Cube] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => USD
[rate] => 1.3000
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => JPY
[rate] => 112.54
)
)
[2] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => BGN
[rate] => 1.9558
)
)
[3] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => CZK
[rate] => 25.428
)
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => DKK
[rate] => 7.4512
)
)
[5] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => EEK
[rate] => 15.6466
)
)
[6] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => GBP
[rate] => 0.84535
)
)
[7] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => HUF
[rate] => 280.85
)
)
[8] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => LTL
[rate] => 3.4528
)
)
[9] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => LVL
[rate] => 0.7091
)
)
[10] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => PLN
[rate] => 4.0914
)
)
[11] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => RON
[rate] => 4.2658
)
)
[12] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => SEK
[rate] => 9.4810
)
)
[13] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => CHF
[rate] => 1.3543
)
)
[14] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => NOK
[rate] => 8.0530
)
)
[15] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => HRK
[rate] => 7.2276
)
)
[16] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => RUB
[rate] => 39.4907
)
)
[17] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => TRY
[rate] => 1.9907
)
)
[18] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => AUD
[rate] => 1.4812
)
)
[19] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => BRL
[rate] => 2.2978
)
)
[20] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => CAD
[rate] => 1.3586
)
)
[21] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => CNY
[rate] => 8.8075
)
)
[22] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => HKD
[rate] => 10.1061
)
)
[23] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => IDR
[rate] => 11757.68
)
)
[24] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => INR
[rate] => 60.8140
)
)
[25] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => KRW
[rate] => 1563.65
)
)
[26] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => MXN
[rate] => 16.6634
)
)
[27] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => MYR
[rate] => 4.1672
)
)
[28] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => NZD
[rate] => 1.8146
)
)
[29] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => PHP
[rate] => 60.177
)
)
[30] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => SGD
[rate] => 1.7893
)
)
[31] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => THB
[rate] => 41.893
)
)
[32] => SimpleXMLElement Object
(
[@attributes] => Array
(
[currency] => ZAR
[rate] => 9.8064
)
)
)
)
)