我的代码:
$url = "https://apilayer.net/api/live?currencies=USD,EUR,GBP&source=USD&format=1";
$json = file_get_contents($url);
$thedata = json_decode($json, true);
echo $thedata['quotes']['USDEUR'];
这是JSON我得到:
"quotes":{
"USDUSD":1,
"USDEUR":0.90629,
"USDGBP":0.63802
}
所以现在我有一个数据库和列名货币。所以我想把货币表变成php。 和货币=像
id - currency
1 - USD
2 - GBP
3 - USD
AND MORE ...
所以我这样做:
$url = "https://apilayer.net/api/live?currencies=USD,EUR,GBP&source=$data[currency]&format=1";
但在回波数据我想打印
echo $thedata['quotes']['USDEUR'];
但我想改变美元TO $数据[货币]
想要这样:
echo $thedata['quotes']['$data[currency]EUR'];
但它只打印“USD”,IWANA PRINT USDEUR。 – melado
把欧元结束,然后... –