fork download
  1. <?php
  2.  
  3.  
  4. $str = '[{"object":"list","hasMore":true,"limit":10,"offset":0,"data":[{"city":{"object":"city","id":15873,"ibgeCode":"3550308","name":"São Paulo","districtCode":"00","district":"São Paulo","state":"SP"}},
  5. {"city":{"object":"city","id":15718,"ibgeCode":"5200050","name":"Abadia de Goiás","districtCode":"05","district":"Abadia de Goiás","state":"GO"}},
  6. {"city":{"object":"city","id":9853,"ibgeCode":"3100104","name":"Abadia dos Dourados","districtCode":"05","district":"Abadia dos Dourados","state":"MG"}}
  7. ]}]';
  8. $json = json_decode($str, true);
  9.  
  10. foreach($json[0]['data'] as $item){
  11. echo $item['city']['name'] .' - '. $item['city']['state'] . PHP_EOL;
  12. }
Success #stdin #stdout 0.02s 52432KB
stdin
Standard input is empty
stdout
São Paulo - SP
Abadia de Goiás - GO
Abadia dos Dourados - MG