This article is mainly for you to share a PHP read local JSON file instance, has a good reference value, I hope to help you. Follow the small series together to see it, hope to help everyone.
{"Goods": [{"Type": 1, "name": "Wow featured", "Product": [{"id": 98, "name": "Leather Coat", "title": "Single barrel original whisky Spring gift Box Limited exclusive", "Titledesc": " Scottish maltose, China Custom Edition "," Price ": 1298.00},{" id ":" The Name ":" Brand Underwear "," title ":" Single barrel original whisky Spring gift Box Limited exclusive 222 "," Titledesc ":" Scottish maltose, China custom version 222 "," Price ": 1298.00}]},{" type ": 2," name ":" Special Merchandise "," Product ": []}]}
2.php file
<?php echo "Get the parameters from the page"; $type = $_get[' type ']; $proId = $_get[' id ']; echo $type. " Product Type "; echo $proId. " Product ID "; Reading data from a file to a PHP variable $json _string = file_get_contents (' Json/data.json '); Use the parameter true to force the JSON string into the PHP array $data = Json_decode ($json _string, true); show up to see//Var_dump ($json _string); Var_dump ($data); Print_r ($data); Product Cycle function Foreachfun ($d, $type, $proId) {foreach ($d ["goods"] as $key = + $value) {if ($value ["type"] = = $t ype) {$results = $value; }} foreach ($results ["Product"] as $key = + $value) {if ($value ["id"] = = $proId) {$result = $value; }} return $result; } $res = Foreachfun ($data, $type, $proId); Print_r ($res);;