0

I have a problem with array_unique() in PHP. Here is my code:

$filterGroupsArray = ['', 'a', 'a', 'b'];
print_r($filterGroupsArray);
array_unique($filterGroupsArray);
print_r($filterGroupsArray);

The output is

Array ( [0] => [1] => a [2] => a [3] => b ) Array ( [0] => [1] => a [2] => a [3] => b )

but I am expecting

Array ( [0] => [1] => a [2] => a [3] => b ) Array ( [0] => [1] => a [2] => b )

What did I do wrong? Thank you very much!

0

1 Answer 1

0

array_unique returns a new array with the duplicate values removed.

$uniqueArray = array_unique($filterGroupsArray);
print_r($uniqueArray);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.