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 the array data format [1,2] at this time, an error may occur
At this time, it should be in array_unique After that, make an array_values
like this: array_values(array_unique(array(1, 1, 2)));
The result is [1,2]