[英]Error on foreach on array of objects
Im having some issues regarding a array of objects, for some reason i cant access the id of each object, it gives me a error of: 我有一些关于对象数组的问题,由于某种原因我无法访问每个对象的ID,它给我一个错误:
ErrorException in SController.php line 51:
Undefined index: id
In my controlller method: 在我的控制方法中:
public function today()
{
$todayMatches = new SportRadarService();
$temp = [];
foreach ($todayMatches->getAllMatchesFromDate() as $match){
array_push($temp,$match["id"]);
}
return $temp;
}
Sample data from "$todayMatches->getAllMatchesFromDate()": 来自“ $ todayMatches-> getAllMatchesFromDate()”的样本数据:
[
{
"id": "sr:11964344",
"scheduled": "2017-08-09T15:00:00+00:00",
},
{
"id": "sr:767667",
"scheduled": "2017-08-012T15:00:00+00:00",
},
....
]
It's a collection, an Object. 这是一个集合,一个对象。 Try:
尝试:
array_push($temp,$match->id);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.