Pangu Posted September 18, 2015 Share Posted September 18, 2015 (edited) with: <?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"; ?> i can read out the closing-number for the first day from a choosen stock in the yahoo-api. -> how can i read out ALL entries for 'Close'? -> in this example it would be: <?php 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"; ?> Edited September 18, 2015 by Pangu Quote Link to comment Share on other sites More sharing options...
Pangu Posted September 18, 2015 Author Share Posted September 18, 2015 found the solution: foreach ($myArray['query']['results']['quote'] as $k => $v) { echo $v['Close'] . " Day" . ($k+1) . "<br />"; } Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 18, 2015 Share Posted September 18, 2015 you would loop over - $myArray['query']['results']['quote'] and then reference the ['close'] element. the following (untested) should work - foreach($myArray['query']['results']['quote'] as $arr){ echo $arr['Close']; } if you want to display a day number/counter, initialize a php variable before the start of the loop, echo and increment it inside the loop to provide the day number. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.