对象数组上的 foreach 出错



我对对象数组有一些问题,由于某种原因我无法访问每个对象的 id,它给了我一个错误:

ErrorException in SController.php line 51:
Undefined index: id

在我的控制器方法中:

public function today()
{
$todayMatches = new SportRadarService();
$temp = [];
foreach ($todayMatches->getAllMatchesFromDate() as $match){
array_push($temp,$match["id"]);
}
return $temp;
}

来自"$todayMatches->getAllMatchesFromDate(("的示例数据:

[
{
"id": "sr:11964344",
"scheduled": "2017-08-09T15:00:00+00:00",
},
{
"id": "sr:767667",
"scheduled": "2017-08-012T15:00:00+00:00",
},
....
]

它是一个集合,一个对象。尝试:

array_push($temp,$match->id);

最新更新