gpt4 book ai didi

php - 数组键索引附带数字

转载 作者:行者123 更新时间:2023-12-03 08:20:29 24 4
gpt4 key购买 nike

我正在以下形式的数组:

[
{
"id": "bitcoin",
"name": "Bitcoin",
"symbol": "BTC",
"rank": "1",
"price_usd": "7598.02",
"price_btc": "1.0",
"24h_volume_usd": "5106040000.0",
"market_cap_usd": "128754238591",
"available_supply": "16945762.0",
"total_supply": "16945762.0",
"max_supply": "21000000.0",
"percent_change_1h": "0.01",
"percent_change_24h": "-5.69",
"percent_change_7d": "-14.2",
"last_updated": "1522317867",
"price_eur": "6162.0702002",
"24h_volume_eur": "4141049500.4",
"market_cap_eur": "104420975040"
},
{
"id": "ethereum",
"name": "Ethereum",
"symbol": "ETH",
"rank": "2",
"price_usd": "415.793",
"price_btc": "0.0552943",
"24h_volume_usd": "1521500000.0",
"market_cap_usd": "40949398071.0",
"available_supply": "98485059.0",
"total_supply": "98485059.0",
"max_supply": null,
"percent_change_1h": "-1.02",
"percent_change_24h": "-9.97",
"percent_change_7d": "-24.69",
"last_updated": "1522317854",
"price_eur": "337.21228093",
"24h_volume_eur": "1233951715.0",
"market_cap_eur": "33210371330.0"
}
]

现在我想在PHP的FOREACH LOOP中获得此数组,但是当我放置此代码时,它将引发语法错误
**<?php echo $price_usd = $myVariable->24h_volume_usd ?>**

因为任何变量都不以数字开头。如何在FOREACH LOOP的帮助下获取 24h_volume_usd 值。
帮帮我
提前致谢。

最佳答案

您可以尝试以下方法:

$data = json_decode($dataStr, true); //When TRUE, returned objects will be converted into associative arrays. 
foreach($data as $val){
echo "\n".$val['24h_volume_eur'];
}

Demo

关于php - 数组键索引附带数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49553733/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com