Home >Backend Development >PHP Tutorial >The difference between braces and curly braces in php json_encode value_PHP tutorial
1. When array is a continuous array starting from 0, the result of json_encode is a string enclosed by []
When the array is an array that does not start from 0 or is not continuous, the result of json_encode is a string in key-value pattern enclosed by {}
Result:
[1,1,1]
Result:
{"1":1,"2":1}
2. When the string is in the pattern [1,1,1], the result parsed by json_decode is an array by default,
When the string is in the pattern {"1":1,"2":1}, the result parsed by json_decode is an object by default. At this time, you can set its second parameter to true to force it to Return array
3. The above situation occurs because PHP cannot distinguish between one-dimensional arrays and two-dimensional arrays, because it is recommended to set the second parameter to true when using json encoding