我使用API连接到第三方网站,该网站返回以下结果:
stdClass Object
(
[timeFrameStart] => 2017-03-11
[timeFrameEnd] => 2017-03-12
[count] => 1
[fixtures] => Array
(
[0] => stdClass Object
(
[date] => 2017-03-11T15:00:00Z
[status] => FINISHED
[matchday] => 37
[homeTeamName] => Home Team
[awayTeamName] => Away Team
[result] => stdClass Object
(
[goalsHomeTeam] => 0
[goalsAwayTeam] => 0
)
)
)
)
我可以使用以下方式获取球队名称:
foreach($details->fixtures as $record) {
echo $record->homeTeamName;
}
然而,我似乎无法弄清楚如何从结果数组中获取goalHomeTeam / goalsAwayTeam值。
答案 0 :(得分:1)
尝试:
foreach($details->fixtures as $record) {
echo $record->homeTeamName . '<br />';
echo $record->result->goalsHomeTeam . '<br />';
echo $record->result->goalsAwayTeam . '<br />';
}
希望这有帮助!