在JSON PHP中获取数组

时间:2016-10-27 20:12:45

标签: php arrays json

我正在试图弄清楚如何从一堆阵列中获得最高的"等级":" VALUE"并且可以访问整个数组。在这种情况下,最高的"":" DIAMOND"。

等级列表(从最高到最低):

CHALLENGER

MASTER

DIAMOND

PLATINUM

GOLD

SILVER

BRONZE

我不知道如何让每个数组数据找到最高层,并根据该数组使用该层获取对其他数据的访问权。

这是JSON文件

{
   "29161162": [
      {
         "name": "Graves's Inquisitors",
         "tier": "DIAMOND",
         "queue": "RANKED_SOLO_5x5",
         "entries": [
            {
               "playerOrTeamId": "29161162",
               "playerOrTeamName": "ForsakenHound",
               "division": "III",
               "leaguePoints": 50,
               "wins": 234,
               "losses": 190,
               "playstyle": "NONE",
               "isHotStreak": false,
               "isVeteran": false,
               "isFreshBlood": false,
               "isInactive": false
            }
         ]
      },
      {
         "name": "Leona's Dervish",
         "tier": "PLATINUM",
         "queue": "RANKED_TEAM_5x5",
         "entries": [
            {
               "playerOrTeamId": "TEAM-4e132820-393f-11e6-8b2a-c81f66daeaa4",
               "playerOrTeamName": "Raging Turtles Alpha",
               "division": "II",
               "leaguePoints": 40,
               "wins": 12,
               "losses": 3,
               "playstyle": "NONE",
               "isHotStreak": false,
               "isVeteran": false,
               "isFreshBlood": false,
               "isInactive": false
            }
         ]
      },
      {
         "name": "Darius's Ritualists",
         "tier": "PLATINUM",
         "queue": "RANKED_TEAM_5x5",
         "entries": [
            {
               "playerOrTeamId": "TEAM-612b20d0-59c3-11e6-ae27-c81f66daeaa4",
               "playerOrTeamName": "Raging Turtles Reborn",
               "division": "II",
               "leaguePoints": 5,
               "wins": 8,
               "losses": 4,
               "playstyle": "NONE",
               "isHotStreak": false,
               "isVeteran": false,
               "isFreshBlood": false,
               "isInactive": false
            }
         ]
      },
      {
         "name": "Kayle's Lancers",
         "tier": "PLATINUM",
         "queue": "RANKED_TEAM_5x5",
         "entries": [
            {
               "playerOrTeamId": "TEAM-989e11c5-8c05-11e6-9e23-c81f66dd7106",
               "playerOrTeamName": "Raging turtles",
               "division": "I",
               "leaguePoints": 0,
               "wins": 5,
               "losses": 0,
               "playstyle": "NONE",
               "isHotStreak": false,
               "isVeteran": false,
               "isFreshBlood": false,
               "isInactive": false
            }
         ]
      }
   ]
}

1 个答案:

答案 0 :(得分:0)

您可以按照此类的值对它们进行分组:

$levels = explode(',', 'BRONZE,SILVER,GOLD,PLATINUM,DIAMOND,MASTER,CHALLENGER');

$tier_data = array();
foreach ($jsona as $unknown_key_id=>&$users) {
  foreach ($users as &$user) {
    $tier_value = array_search($user->tier, $levels);
    $tier_data[$tier_value][] = $user;
  }
}

die('<pre>'.print_r($tier_data,true));