【发布时间】:2012-03-15 19:34:39
【问题描述】:
我希望能够从一种货币转换为另一种货币,我找到了一个 XML API here,它涵盖了我在网站上使用的大多数货币,但我遇到了问题是如何使用此 XML 文件从一种货币转换为另一种货币。
显然,我已将货币及其汇率解析并添加到这样的数组中:
Array
(
[USD] => 1.3412
[JPY] => 107.99
[BGN] => 1.9558
...
兑换汇率的公式如下:
$from = 'GBP'; // The currency can be dynamic to a different currency
$to = 'USD'; // this one too
$amount = 400;
$converted_amount = round($amount / $rate, 2);
$rate 是我不知道该怎么做 - 如何转换成可分割为$amount 的汇率。
【问题讨论】:
-
我不确定我是否理解。您不能将
$amount乘以您数组中定义的汇率吗?