1. When the array is a contiguous array starting at 0, the result of the Json_encode is a string enclosed by []
When the array is not starting at 0 or not contiguous, the result of the Json_encode is a string of key-value patterns enclosed by {}
Copy Code code as follows:
$test = Array ();
$test [] = 1;
$test [] = 1;
$test [] = 1;
echo Json_encode ($test);
Results:
[1,1,1]
Copy Code code as follows:
$test = Array ();
$test [] = 1;
$test [] = 1;
$test [] = 1;
unset ($test [0]);
echo Json_encode ($test);
Results:
{"1": 1, "2": 1}
2. When the string is [1,1,1] This pattern, the default parsing result of Json_decode is an array,
When the string is {"1": 1, "2": 1} This mode, the result of the Json_decode default resolution is an object, at which point the second argument can be set to true to force it to return an array
3. Because PHP cannot differentiate between one-dimensional and two-dimensional arrays, the above situation occurs because the second parameter is recommended to TRUE when using JSON encoding