fork download
  1. <?php
  2. $json = '[{"id":1,"name":"Drew"},{"id":2,"name":"Joyce"},{"id":3,"name":"Vick"}]';
  3.  
  4. $result = json_decode($json, true);
  5.  
  6. foreach ($result as $item) {
  7. echo 'id: ', $item['id'],
  8. ', name: ', $item['name'],
  9. PHP_EOL;
  10. }
  11.  
  12. // Can also reference by array index
  13. echo 'Item #2 name: ', $result[1]['name'], PHP_EOL;
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
id: 1, name: Drew
id: 2, name: Joyce
id: 3, name: Vick
Item #2 name: Joyce