PHP查询数组某值

如查询BTC时.把 里面的BTC各数据取出来.
查询ETH时.就把里面ETH里各数据取现来..

{
    "data": {
        "1": {
            "id": 1, 
            "name": "Bitcoin", 
            "symbol": "BTC", 
            "website_slug": "bitcoin", 
            "rank": 1, 
            "circulating_supply": 17040312.0, 
            "total_supply": 17040312.0, 
            "max_supply": 21000000.0, 
            "quotes": {
                "USD": {
                    "price": 8141.89, 
                    "volume_24h": 5978330000.0, 
                    "market_cap": 138740345870.0, 
                    "percent_change_1h": 0.14, 
                    "percent_change_24h": -1.98, 
                    "percent_change_7d": -7.2
                }
            }, 
            "last_updated": 1526636671
        }, 
        "1027": {
            "id": 1027, 
            "name": "Ethereum", 
            "symbol": "ETH", 
            "website_slug": "ethereum", 
            "rank": 2, 
            "circulating_supply": 99509087.0, 
            "total_supply": 99509087.0, 
            "max_supply": null, 
            "quotes": {
                "USD": {
                    "price": 683.134, 
                    "volume_24h": 2455830000.0, 
                    "market_cap": 67978040574.0, 
                    "percent_change_1h": 0.22, 
                    "percent_change_24h": -2.81, 
                    "percent_change_7d": -2.68
                }
            }, 
            "last_updated": 1526636958
        }, 
        "52": {
            "id": 52, 
            "name": "Ripple", 
            "symbol": "XRP", 
            "website_slug": "ripple", 
            "rank": 3, 
            "circulating_supply": 39189968239.0, 
            "total_supply": 99992233977.0, 
            "max_supply": 100000000000.0, 
            "quotes": {
                "USD": {
                    "price": 0.674545, 
                    "volume_24h": 353429000.0, 
                    "market_cap": 26435397126.0, 
                    "percent_change_1h": 0.14, 
                    "percent_change_24h": -3.24, 
                    "percent_change_7d": -4.18
                }
            }, 
            "last_updated": 1526636941
        }, 
        "1975": {
            "id": 1975, 
            "name": "ChainLink", 
            "symbol": "LINK", 
            "website_slug": "chainlink", 
            "rank": 100, 
            "circulating_supply": 350000000.0, 
            "total_supply": 1000000000.0, 
            "max_supply": null, 
            "quotes": {
                "USD": {
                    "price": 0.450519, 
                    "volume_24h": 1371140.0, 
                    "market_cap": 157681650.0, 
                    "percent_change_1h": 0.15, 
                    "percent_change_24h": -6.09, 
                    "percent_change_7d": -9.53
                }
            }, 
            "last_updated": 1526636956
        }
    }, 
    "metadata": {
        "timestamp": 1526636754, 
        "num_cryptocurrencies": 1593, 
        "error": null
    }
}
阅读 2k
2 个回答
$arr = $arr['data'];

$arr1 = array_filter($arr, function ($item){
    return $item['symbol'] == 'BTC';
});
var_dump($arr1);
function getData($type) {
  $data = obj["data"];
  foreach($data as  $item) {
    if($item['symbol'] == $type) {
       return $item;
    }
  }
}
$btcData = getData("BTC");
推荐问题
宣传栏