Last active
November 6, 2017 17:14
-
-
Save yvan-sraka/3da055748bf23cbfedf62abb3e929600 to your computer and use it in GitHub Desktop.
How to open a JSON file in PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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