为了账号安全,请及时绑定邮箱和手机立即绑定

PHP查询数组某值

PHP查询数组某值

海绵宝宝撒 2019-05-21 10:08:43
如查询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}}
查看完整描述

2 回答

?
呼如林

TA贡献1798条经验 获得超3个赞

$arr=$arr['data'];
$arr1=array_filter($arr,function($item){
return$item['symbol']=='BTC';
});
var_dump($arr1);
                            
查看完整回答
反对 回复 2019-05-21
?
ITMISS

TA贡献1871条经验 获得超8个赞

functiongetData($type){
$data=obj["data"];
foreach($dataas$item){
if($item['symbol']==$type){
return$item;
}
}
}
$btcData=getData("BTC");
                            
查看完整回答
反对 回复 2019-05-21
  • 2 回答
  • 0 关注
  • 687 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信