removing duplicates from an array in php
-
03-06-2021 - |
Question
I want to remove duplicate elements from an array in php. Following is the structure of the array
Array
(
[0] => Array
(
[0] => xllga@hotmail.com
[1] => bounce@abc.com
[2] => 20120416135504.21734.qmail@abc.com
[3] => xllga@hotmail.com
[4] => info@abc.com
[5] => info@abc.com
[6] => xllga@hotmail.com
[7] => xllga@hotmail.com
)
)
How to go about it ?
Solution
http://php.net/manual/en/function.array-unique.php
$new_unique_array = array_unique($your_array[0]);
Hope that helps, Stefan
OTHER TIPS
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.
Try array_unique()
:
$newArray = array_unique($oldArray);
From the docs:
[
array_unique()
] Takes an input array and returns a new array without duplicate values.
No array_unique() solution. not so smart:)
array_keys(array_flip($array));
If use your array, $array = $yourArray[0];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow