Drupal - 从数组中获取值

Drupal - get value from array

可能是我的问题,但我无法从以下数组中获取值:

http://picpaste.com/pics/Untitled-2YV5V2Im.1427134235.png

我想要的是创建一个 table,其中 headers 是这样的:

主队名称 |客队名称 |匹配 home_goals |匹配 away_goals

然后我有 9 行值。

到目前为止我的代码:

$json = json_decode($server_output, true);
$days= $json['Calendar']['championship']['StageRound'][0]['matches'];

$header = ['HomeTeam name', 'AwayTeam name', 'Match home_goals', 'Match away_goals'];
$row = array();

foreach ($days as $key => $value) {
  ... here, I get always an error saying 'HomeTeam' is not an index...
}

$table = theme('table', array('header' => $header, 'rows' => $rows));

return $table;

有什么帮助吗? 谢谢!

编辑:

添加了这段代码:

foreach ($days as $key => $value) {
  $hometeam = $days[0]['HomeTeam']['name'];
  $awayteam= $days[0]['AwayTeam']['name'];
  dpm($hometeam . ' - ' . $awayteam);
}

我在 for 循环内的两行中都有索引 [0],但我需要它是从 0 到 9(数组的长度。这将解决我的问题。

Foreach 已经遍历 matches 数组,因此您不需要 [0]。选择:

  $hometeam = $value['HomeTeam']['name'];
  $awayteam= $value['AwayTeam']['name'];

  $hometeam = $days[$key]['HomeTeam']['name'];
  $awayteam= $days[$key]['AwayTeam']['name'];

如果你喜欢通过键访问数组...