According to the PHP documentation, array_unique removes duplicate values and sorts the values treated as string at first.
When you take the following snippet in mind:
// define a simple array of strings, unordered
$brands = [ "BMW", "Audi", "BMW", "Chrysler", "Daewoo"];
// distinct the values, and sort them
echo array_unique($brands, SORT_STRING);
I would expect the output to be:
expected: {"0":"Audi","1":"BMW","3":"Chrysler","4":"Daewoo"}
actual : {"0":"BMW","1":"Audi","3":"Chrysler","4":"Daewoo"}
The question is: why doesn't array_unique sort these values? Changing the sort_flags parameter to any of the four alternatives, or leaving it empty, has no effect either.
According to other SO questions, like "Why does array unique sort the values" I'm probably missing something obvious here. Also, using array_values(array_unique($brands))
, as stated as an answer in this question doesn't seem to work either.
Update: As stated in the useful comments and answers, the sort_flags parameter is actually an inner compare behavior, or equality operator, sort of speak.