1

I have an array in variable $votes. print_r($votes) gives us:

Array ( [0] => 1 [1] => 1 [2] => 1 ) 

So we have three values, all of which are set to 1.

Now, I want to make the array only have unique values, meaning that if there are three values that match 1, then remove two of them.

To achieve this, I tried array_unique($votes); but it did not remove any values. Why?!

Henrik Petterson
  • 6,862
  • 20
  • 71
  • 155

1 Answers1

3

You have to assign the output of array_unique to the array again like this:

$votes = array_unique($votes);

As a reference you can look at the manual: http://php.net/manual/en/function.array-unique.php

And a quote from there:

Takes an input array and returns a new array without duplicate values.

Rizier123
  • 58,877
  • 16
  • 101
  • 156