After PHP array_unique json_encode needs to be noted

  • 2020-03-31 21:28:30
  • OfStack

For example: array_unique(array(1, 1, 2));
His result is
Array (2) {
[0] = >
Int (1)
[2] = >
Int (2)
}

This is not an numeric array, just do json_encode, which outputs a json object instead of an array
{" 0 ": 1," 2 ", 2}

If the array data format [1,2] is required by js on the page, an error may occur

You should do array_values after array_unique
Array_values (array_unique(array(1, 1, 2));

The result is [1,2].

Related articles: