Php 对象数组上的foreach错误
我对对象数组有一些问题,由于某些原因,我无法访问每个对象的id,这给了我一个错误:Php 对象数组上的foreach错误,php,arrays,laravel,laravel-5,laravel-5.3,Php,Arrays,Laravel,Laravel 5,Laravel 5.3,我对对象数组有一些问题,由于某些原因,我无法访问每个对象的id,这给了我一个错误: ErrorException in SController.php line 51: Undefined index: id 在我的Controller方法中: public function today() { $todayMatches = new SportRadarService(); $temp = []; foreach ($todayMat
ErrorException in SController.php line 51:
Undefined index: id
在我的Controller方法中:
public function today()
{
$todayMatches = new SportRadarService();
$temp = [];
foreach ($todayMatches->getAllMatchesFromDate() as $match){
array_push($temp,$match["id"]);
}
return $temp;
}
来自“$todayMatches->getAllMatchesFromDate()”的示例数据:
这是一个集合,一个对象。尝试:
array_push($temp,$match->id);
我猜match不是数组,而是对象。那不是集合
array_push($temp,$match->id);