Reputation: 229
I want to remove duplicate elements from an array in php. Following is the structure of the array
Array
(
[0] => Array
(
[0] => [email protected]
[1] => [email protected]
[2] => [email protected]
[3] => [email protected]
[4] => [email protected]
[5] => [email protected]
[6] => [email protected]
[7] => [email protected]
)
)
How to go about it ?
Upvotes: 1
Views: 222
Reputation: 1179
No array_unique() solution. not so smart:)
array_keys(array_flip($array));
If use your array, $array = $yourArray[0];
Upvotes: 0
Reputation: 22810
Try array_unique
.
Code :
<?php
$arr = array_unique($arr);
?>
array array_unique ( array $array [, int $sort_flags = SORT_STRING ] )
Takes an input array and returns a new array without duplicate values.
Upvotes: 7
Reputation: 2075
http://php.net/manual/en/function.array-unique.php
$new_unique_array = array_unique($your_array[0]);
Hope that helps, Stefan
Upvotes: 2
Reputation: 101473
Try array_unique()
:
$newArray = array_unique($oldArray);
From the docs:
[
array_unique()
] Takes an input array and returns a new array without duplicate values.
Upvotes: 3