Reputation: 7094
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?!
Upvotes: 1
Views: 103
Reputation: 59681
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.
Upvotes: 3