fork download
  1. <?php
  2.  
  3. // your code goes here
  4. $arr = array('foo' => 'bar', 2 => 'test');
  5. $json = json_encode($arr);
  6. var_dump($json);
  7. $arr = json_decode($json, true);
  8. var_dump($arr);
  9. foreach ($arr as $k => $v) {
  10. echo "$k => $v\n";
  11. }
Success #stdin #stdout 0.02s 20568KB
stdin
Standard input is empty
stdout
string(24) "{"foo":"bar","2":"test"}"
array(2) {
  ["foo"]=>
  string(3) "bar"
  [2]=>
  string(4) "test"
}
foo => bar
2 => test