Skip to content

Instantly share code, notes, and snippets.

@rrezzik
Created May 17, 2012 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rrezzik/2720011 to your computer and use it in GitHub Desktop.
Save rrezzik/2720011 to your computer and use it in GitHub Desktop.
Using json_decode to go from JSON to PHP array
<?php
// The response from an API call..
$json_string = '{"array" : ["a", "b", "c"]}';
// Use json_decode to get a JSON object as a PHP associative array
$json_obj = json_decode($json_string, true);
// Iterate through it for fun
foreach ($json_obj['array'] as $value) {
echo $value . "\n";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment