Parsing JSON Array with PHP foreach



The below code can be used to parse JSON array −

Example

 Live Demo

<?php
$json_array ='{
   "values": {
      "a": "abc",
      "d": 0,
      "efg": 349
   }
}';
$array = json_decode($json_array, true);
foreach($array as $values) {
   echo $values['efg'];
   echo $values['d'];
   echo $values['a'];
}

Output

This will produce the following output −

3490abc
Updated on: 2020-04-07T11:11:49+05:30

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements