foreach对象数组出错

时间:2017-07-17 12:02:51

标签: php arrays laravel laravel-5 laravel-5.3

我有一些关于对象数组的问题,由于某些原因我无法访问每个对象的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",
},
....
]

1 个答案:

答案 0 :(得分:0)

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

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