Reputation: 107
I have an array $tmp:
$a = array(0 => 49, 1 => 49, 2 => 49);
after using array_unique($tmp)
I'm getting this output:
Array
(
[0] => 49
[1] => 49
[2] => 49
)
and I want to get
Array
(
[0] => 49
)
What am I doing wrong? Im new in PHP
Upvotes: 0
Views: 1851
Reputation: 46900
You don't only need to call that function you need to use the returned value as well. Do
$tmp=array_unique($tmp);
Just calling that function and not picking up the returned value does no good.
There are some functions that operate on the original variable and hence you dont need to pick up their ret val for example sort()
but array_unique()
is not one of them. Always refer to http://www.php.net/functionName to find out
Upvotes: 8
Reputation: 64
$input = array(49,49,49);
$result = array_unique($input);
print_r($result);
Upvotes: 3