Currently, the literal naming method is not supported in PHP.
The small partners at the front end know that the method of defining an object in JS with literal literals can be as follows:
var o = {' name ': ' Tom ', ' url ': ' Www.baidu.com ' };alert (o.name);
But in PHP this defines the object:
$o = {"Name": "Tom", "url": "Www.baidu.com" };
The error will be
Parse error: syntax error, unexpected '{' in D:\server\htdocs\xm\data\04_product_ select.php on line 9
So when you need to use JSON, you can try the form of PHP array, and less use of the form of objects, it can be simpler and more intuitive (at present my point of view, perhaps not enough objective, look treatise). Then use the Json_enconde ($arr), the JSON format encoding, the method is as follows
$arr = [ ' name ' = ' Tom ', ' age ' = ]; $json = Json_encode ($arr);
When I consulted the Nanyi teacher's blog article " using JSON in PHP ", I saw what Mr. Ruan said, "JavaScript does not support associative arrays " (see). But did not find the information to refute him, or refute himself, so posted here, hope to be able to solve their own in the future, but also hope that you can guide twos, greatly appreciated!
But the last word:Json_enconde () converts an indexed array (indexed array) to array format only, and the associative array (associative array) to the object format. This feature should be kept in mind!
JSON uses--php to define a literal object using the JSON data format