For example: array_unique(array(1, 1, 2));
The result is
array(2) {
[0]=>
int(1)
[2]=>
int(2)
}
This is not a numeric array. Doing json_encode directly will output a json object instead of an array
{"0":1,"2":2}
If the js on the page needs [1,2 at this time ]This array data format may cause errors
At this time, you should make array_values after array_unique
Like this: array_values(array_unique(array(1, 1, 2)));
The result is [1,2 ]
The above introduces the json_encode need to pay attention to after json_encode php array_unique, including the content of json_encode. I hope it will be helpful to friends who are interested in PHP tutorials.