【发布时间】:2011-04-03 18:50:14
【问题描述】:
我有 XML 文件,其中有货币和汇率的名称。我想将这些货币和汇率成对保存到一个数组中,但它不起作用,当我用 foreach 回显数组时,只出现最后一个。 这是我的代码:
<?php
$xml = simplexml_load_file("http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml");
$array=array();
foreach ($xml->children() as $cubeMain) {
foreach ($cubeMain->children() as $cubeTime) {
echo "Kursid seisuga: " . $cubeTime['time'];
foreach ($cubeTime->children() as $cubeCurr) {
$currency=$cubeCurr['currency'];
$rate=$cubeCurr['rate'];
$array = array((string)$currency => $rate);
echo $currency . " " . $rate . "<br />";
}
}
}
foreach ($array as $currency => $rate){
echo "$currency: $rate\n";
}
?>
【问题讨论】:
-
(sidenote) 在pear.php.net/package/Services_ExchangeRates有一个 PEAR 包
-
我觉得这么小的东西有点矫枉过正,我不需要你转换:)但是谢谢!