Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数组键索引随数字一起提供_Php_Variables_Foreach_Syntax_Syntax Error - Fatal编程技术网

Php 数组键索引随数字一起提供

Php 数组键索引随数字一起提供,php,variables,foreach,syntax,syntax-error,Php,Variables,Foreach,Syntax,Syntax Error,我正在处理一个数组,其格式如下: [ { "id": "bitcoin", "name": "Bitcoin", "symbol": "BTC", "rank": "1", "price_usd": "7598.02", "price_btc": "1.0", "24h_volume_usd": "5106040000.0", "market_cap_usd":

我正在处理一个数组,其格式如下:

[
    {
        "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"
    }
]

现在我想在FOREACH循环中用PHP获取这个数组,但当我将此代码放入时,它会抛出一个语法错误

**<?php echo $price_usd = $myVariable->24h_volume_usd ?>**
****
因为任何变量都不是以数字开头的。如何在FOREACH循环的帮助下获得24小时交易量\u 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'];
}
您可以尝试以下方法:

$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'];
}

您是否尝试过使用数组索引。i、 e:
$myVariable['24h\u volume\u usd']
@B.Desai,是的,我做了,但它抛出了一个错误,无法将stdClass类型的对象用作arraypost您的完整代码您尝试过数组索引了吗。i、 e:
$myVariable['24h\u volume\u usd']
@B.Desai,是的,我做了,但它抛出了一个错误,无法使用stdClass类型的对象作为完整的arraypostcode@Boyka,你可以从这里得到帮助:我做了,你会喜欢这些问题吗。对我来说也是吗?:)@博伊卡,你可以从这里得到帮助:我做了,你会喜欢这些问题吗。对我来说也是吗?:)