Parsing nested JSON to retrieve nested array values

后端 未结 1 1170
礼貌的吻别
礼貌的吻别 2021-02-04 21:16

I am trying to get some specific fields out of this Json. I have already managed to retrieve the ones in the first level but I need to get some out of the data field. I would li

1条回答
  •  梦谈多话
    2021-02-04 22:06

    How about this?

    $stuff = json_decode($json, true);
    
    $results = array();
    
    foreach($stuff['response']['data'] as $chunk) {
      $artist = $chunk['artist'];
      $id   = $artist['id'];
      $name = $artist['name'];
    
      $rank = $chunk['rank'];
    
      $tuple = array($id, $name, $rank);
    
      $results[] = $tuple;
    }
    

    0 讨论(0)
提交回复
热议问题