PHP Iterate through arrays in object within an array - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Monday, June 7, 2021

PHP Iterate through arrays in object within an array

i have a pretty weird json here. Im trying to iterate through every subscription object and get some data

Here is the 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"
            ]
         }
      ]
   }
}

The code i tried was:

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

Im just getting a lot of errors. Let me know what the correct approach would be. My goal is to mainly get the name & expirey data



source https://stackoverflow.com/questions/67863122/php-iterate-through-arrays-in-object-within-an-array

No comments:

Post a Comment