如何从以下数组中获取特定项目。我想获取接近的值。
在这种情况下我该怎么办?
$ data = json_decode(file_get_contents($ req_url),true);
// print_r($ data); //提供以下数组;
// Array([图表] => Array([结果] => Array([0] => Array([meta] => Array([currency] => USD [symbol] => SEAS [exchangeName] = > NYQ [instrumentType] =>股权[firstTradeDate] => 1366378200 [regularMarketTime] => 1588622401 [gmtoffset] => -14400 [timezone] => EDT [exchangeTimezoneName] => America / New_York [regularMarketPrice] => 14.55 [chartPreviousClose] => 14.11 [previousClose] => 14.11 [scale] => 3 [priceHint] => 2 [currentTradingPeriod] => Array([pre] => Array([timezone] => EDT [end] => 1588599000 [start] => 1588579200 [gmtoffset] => -14400)[常规] =>数组([时区] => EDT [结束] => 1588622400 [开始] => 1588599000 [gmtoffset] => -14400)[post] =>数组([timezone] => EDT [end] => 1588636800 [start] => 1588622400 [gmtoffset] => -14400))[tradingPeriods] => Array([0] => Array([0] => Array([时区] => EDT [结束] => 1588622400 [开始] => 1588599000 [gmtoffset] => -14400)))))[dataGranularity] => 5m [range] => 1d [validRanges] => Array([0] = > 1天[1] = > 5d [2] => 1mo [3] => 3mo [4] => 6mo [5] => 1y [6] => 2y [7] => 5y [8] => 10y [9] => ytd [10] => max))[timestamp] =>数组([0] => 1588599000 [1] => 1588599300 [2] => 1588599600 [3] => 1588599900 [4] => 1588600200 [5] => 1588600500)[指标] =>数组([quote] =>数组([0] =>数组([open] =>数组([0] => 13.3599996567 [1] => 13.8599996567 [2] => 13.720000267 [3 ] => 13.8800001144 [4] => 14.0349998474 [5] => 14.051199913)[关闭] =>数组([0] => 13.9499998093 [1] => 13.7299995422 [2] => 13.8400001526 [3] => 14.0450000763 [4] ] => 14.0600004196 [5] => 14.1899995804)[高] =>数组([0] => 14 [1] => 13.8599996567 [2] => 13.9399995804 [3] => 14.0900001526 [4] => 14.1000003815 [5] ] => 14.2600002289)[低] =>数组([0] => 13.1099996567 [1] => 13.5900001526 [2] => 13.720000267 [3] => 13.8699998856 [4] => 13.8509998322 [5] => 14)[ volume] =>数组([0] => 124733 [1] => 49489 [2] => 51657 [3] => 48362 [4] => 34055 [5] => 36566)))))))[错误] =>));
$close= $data['chart']['result']['indicators']['close'] ;
echo $close;
您需要:
<?php
$data = json_decode(file_get_contents($req_url),true);
$close = $data['chart']['result'][0]['meta']['currentTradingPeriod']['pre']['regular']['post']['tradingPeriods'][0][0]['validRanges']['timestamp']['indicators']['quote'][0]['open']['close'];
echo $close;
?>