如何在PHP中访问嵌套的JSON数组值

时间:2019-11-14 21:00:10

标签: php html json

我正在尝试从这些JSON数组访问辅助,目标和积分值。请帮忙!

我正在使用这些数据来填充学校的迷你幻想曲棍球项目。我需要遍历这些数据并更新数据库(PHPmyAdmin)中的行,以便随后可以显示幻想队的实时统计信息。

{
  "copyright" : "NHL and the NHL Shield are registered trademarks of the National Hockey League. NHL and NHL team marks are the property of the NHL and its teams. © NHL 2019. All Rights Reserved.",
  "stats" : [ {
    "type" : {
      "displayName" : "statsSingleSeason"
    },
    "splits" : [ {
      "season" : "20192020",
      "stat" : {
        "timeOnIce" : "398:18",
        "assists" : 13,
        "goals" : 13,
        "pim" : 4,
        "shots" : 77,
        "games" : 20,
        "hits" : 9,
        "powerPlayGoals" : 4,
        "powerPlayPoints" : 7,
        "powerPlayTimeOnIce" : "70:00",
        "evenTimeOnIce" : "327:56",
        "penaltyMinutes" : "4",
        "faceOffPct" : 56.63,
        "shotPct" : 16.9,
        "gameWinningGoals" : 2,
        "overTimeGoals" : 0,
        "shortHandedGoals" : 0,
        "shortHandedPoints" : 0,
        "shortHandedTimeOnIce" : "00:22",
        "blocked" : 13,
        "plusMinus" : 10,
        "points" : 26,
        "shifts" : 490,
        "timeOnIcePerGame" : "19:54",
        "evenTimeOnIcePerGame" : "16:23",
        "shortHandedTimeOnIcePerGame" : "00:01",
        "powerPlayTimeOnIcePerGame" : "03:30"
      }
    } ]
  } ]
}

到目前为止,这是我的代码,我只需要弄清楚foreach循环。

$json = file_get_contents('https://statsapi.web.nhl.com/api/v1/people/8479318/stats?stats=statsSingleSeason&season=20192020');
$obj = json_decode($json);

0 个答案:

没有答案