Php 在echo中打印$data?

Php 在echo中打印$data?,php,json,Php,Json,我的代码: $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

我的代码:

$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
}
现在我有了一个数据库和列名currency。所以我想把currency表放到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'];
但我想把美元换成美元数据[货币]

像这样:

echo $thedata['quotes']['$data[currency]EUR'];
尝试:

试试这个:

echo $thedata['quotes']['$data[currency]'].$thedata['quotes']['EUR'];

这个。将两个字符串组合成一个回音,因此您应该可以得到所需的输出。

但它只打印“USD”,IWANA打印USDEUR.THX U,但它不起作用?什么是$data[“currency”?你能用这些信息修改你的主要帖子吗?echo$thedata['quotes'][$data['currency]].]美元];这是它的工作
echo $thedata['quotes']['$data[currency]'].$thedata['quotes']['EUR'];