1. When array is a continuous array starting from 0, the result of json_encode is a string enclosed [].
When array is an array that does not start from 0 or is not continuous, the result of json_encode is a string in the key-value mode enclosed {}.
Copy codeThe Code is as follows:
$ Test = array ();
$ Test [] = 1;
$ Test [] = 1;
$ Test [] = 1;
Echo json_encode ($ test );
Result:
[1, 1]
Copy codeThe Code is as follows:
$ Test = array ();
$ Test [] = 1;
$ Test [] = 1;
$ Test [] = 1;
Unset ($ test [0]);
Echo json_encode ($ test );
Result:
{"1": 1, "2": 1}
2. When the string is in the [, 1] mode, the result parsed by json_decode is an array by default,
When the string is in the {"1": 1, "2": 1} mode, the result parsed by json_decode is an object by default, in this case, you can set its second parameter to true to force it to return an array.
3. Because php cannot distinguish between a one-dimensional array and a two-dimensional array, the above situation occurs, because it is recommended to set the second parameter to true when using json encoding.