使用:
<?php
$data = file_get_contents("http://query.yahooapis.com/v1/public/yql?env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json&q=select%20*%20from%20yahoo.finance.historicaldata%20where%20startDate=%272014-01-01%27%20and%20endDate=%272014-01-10%27%20and%20symbol=%27YHOO%27");
$myArray = json_decode($data, true);
/*
echo "<pre>";
var_dump( $myArray );
echo "</pre>";
*/
echo $myArray['query']['results']['quote'][0]['Close']," DayX";
?>
我可以读出第一天的结束号码。
- &GT;我怎么能读出'关闭'的所有条目? - &GT;在这个例子中它将是:
echo $myArray['query']['results']['quote'][0]['Close']," Day1";
echo $myArray['query']['results']['quote'][1]['Close']," Day2";
echo $myArray['query']['results']['quote'][2]['Close']," Day3";
...
echo $myArray['query']['results']['quote'][6]['Close']," Day7";
答案 0 :(得分:1)
您需要使用foreach
循环来执行此操作。
foreach ($myArray['query']['results']['quote'] as $k => $v) {
echo $v['Close'] . " Day" . ($k+1) . "<br />";
}
在每一行的末尾加<br />
会添加一个换行符,假设这是echo
到浏览器;