在PHP中迭代stdClass对象时,我不';t设法获取一个变量(日期)
与此类似: 但是我需要得到这个stdClass对象的日期[2020-03-20],[2020-02-28]变量:在PHP中迭代stdClass对象时,我不';t设法获取一个变量(日期),php,object,multidimensional-array,stdclass,alpha-vantage,Php,Object,Multidimensional Array,Stdclass,Alpha Vantage,与此类似: 但是我需要得到这个stdClass对象的日期[2020-03-20],[2020-02-28]变量: stdClass Object ( [2020-03-20] => stdClass Object // <- this is what I need ( [1. open] => 711.2600 [2. high] => 806.9800 [3. low] =&
stdClass Object
(
[2020-03-20] => stdClass Object // <- this is what I need
(
[1. open] => 711.2600
[2. high] => 806.9800
[3. low] => 350.5100
[4. close] => 427.5300
[5. volume] => 298764633
)
[2020-02-28] => stdClass Object // <- this is what I need
(
[1. open] => 673.6900
[2. high] => 968.9899
[3. low] => 611.5200
[4. close] => 667.9900
[5. volume] => 473506012
) ...
stdClass对象
(
[2020-03-20]=>stdClass对象//711.2600
[2.高]=>806.9800
[3.低]=>350.5100
[4.关闭]=>427.5300
[5.卷]=>298764633
)
[2020-02-28]=>stdClass对象//673.6900
[2.高]=>968.9899
[3.低]=>611.5200
[4.关闭]=>667.9900
[5.卷]=>473506012
) ...
到目前为止,我可以得到$open,$high。。。变量,但不是日期变量
$API_KEY = "demo";
$symbol = "TSLA";
$company= "Tesla";
$startDate = "2020-03-01";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,("https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=".$symbol."&apikey=".$API_KEY)); // daily adjusted close
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
$result = json_decode($server_output);
$Array = $result->{'Monthly Time Series'};
foreach($Array as $obj){
// THIS IS WHAT I NEED => echo '$date: '.$date.': <BR>'; // THIS DOESN'T WORK, $date is not defined.
$open=$obj->{'1. open'};
$high=$obj->{'2. high'};
$low=$obj->{'3. low'};
$close=$obj->{'4. close'};
$volume=$obj->{'5. volume'};
$API_KEY=“demo”;
$symbol=“TSLA”;
$company=“特斯拉”;
$startDate=“2020-03-01”;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,(“https://www.alphavantage.co/query?function=TIME_SERIES_MONTHLY&symbol=“$symbol.”&apikey=“.API_-KEY”);//每日调整收盘价
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$server\u output=curl\u exec($ch);
卷曲关闭($ch);
$result=json\u decode($server\u输出);
$Array=$result->{'Monthly Time Series'};
foreach($数组作为$obj){
//这就是我需要的=>回显“$date:”.$date.:
”;//这不起作用,$date没有定义。
$open=$obj->{'1.open'};
$high=$obj->{'2.high'};
$low=$obj->{'3.low'};
$close=$obj->{'4.close'};
$volume=$obj->{'5.volume'};
谢谢这非常简单,我不敢相信我以前没有想到这一点,我只是将阵列从: foreach($dataForAllDays作为$obj){ 到 foreach($DATAFORALLDYSAS$date=>$obj){ $date($key)是我想要的日期变量