首页 > 解决方案 > PHP遍历数组内对象中的数组

问题描述

我这里有一个很奇怪的 json。我试图遍历每个subscription对象并获取一些数据

这是json

{
   "result":"success",
   "data":{
      "subscriptions":[
         {
            "name":"app_generator",
            "expirey":1628188363942,
            "hwids":3,
            "hwids_used":[
               "dc253a62ea65cd92c6cb26f15330cf4a8f9e5c3ecf7caae161a3f97de4c84515",
               "efede5757f512f9eae1d600302ca5c4e6a3cadb0658310c91c6da2ada68175f4"
            ]
         },
         {
            "name":"apple",
            "expirey":1625596518277,
            "hwids":2,
            "hwids_used":[
               "dc253a62ea65cd92c6cb26f15330cf4a8f9e5c3ecf7caae161a3f97de4c84515",
               "dc253a62ea65cd92c6cb26f15330cf4a8f9e5c3ecf7caae161a3f97de4c84515a"
            ]
         }
      ]
   }
}

我试过的代码是:

foreach($json['result']['data']['subscriptions'] as $a)
{
  //print_r($a);
  $expirey = $a['expirey']
}

我只是收到很多错误。让我知道正确的方法是什么。我的目标是主要获取name&expirey数据

标签: phparraysjsonnested

解决方案


推荐阅读