Skip to content

Instantly share code, notes, and snippets.

@yvan-sraka
Last active November 6, 2017 17:14
Show Gist options
  • Save yvan-sraka/3da055748bf23cbfedf62abb3e929600 to your computer and use it in GitHub Desktop.
Save yvan-sraka/3da055748bf23cbfedf62abb3e929600 to your computer and use it in GitHub Desktop.
How to open a JSON file in PHP
<?php
/*
* Open example.json file,
* parse it into a $json array
*/
$string = file_get_contents("example.json", FILE_USE_INCLUDE_PATH);
$json = json_decode($string, true);
/*
* Print few test values
*/
echo $json["books"]["programming"][2]["name"]."<br/>";
// => "Land of Lisp"
echo $json["books"]["programming"][0]["price"]."<br/>";
// => 26.00
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment