2017-07-17 41 views
0

林有关于对象的数组一些问题,出于某种原因,我不能访问每个对象的ID的foreach,它给我的错误:错误上对象的数组

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

在我controlller方法:从 “$ todayMatches-> getAllMatchesFromDate()”

public function today() 
    { 
     $todayMatches = new SportRadarService(); 
     $temp = []; 

     foreach ($todayMatches->getAllMatchesFromDate() as $match){ 
      array_push($temp,$match["id"]); 
     } 
     return $temp; 

    } 

的样本数据:

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

我想匹配不是一个数组,它是一个对象。 –

回答

0

这是一个收藏品n,一个对象。尝试:

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

那不是收集 –