1

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 ?

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
Deepak
  • 229
  • 1
  • 4
  • 15

4 Answers4

7

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.

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
3

Try array_unique():

$newArray = array_unique($oldArray);

From the docs:

[array_unique()] Takes an input array and returns a new array without duplicate values.

Bojangles
  • 99,427
  • 50
  • 170
  • 208
2

http://php.net/manual/en/function.array-unique.php

$new_unique_array = array_unique($your_array[0]);

Hope that helps, Stefan

ExternalUse
  • 2,053
  • 2
  • 25
  • 37
0

No array_unique() solution. not so smart:)

array_keys(array_flip($array));

If use your array, $array = $yourArray[0];

tosin
  • 1,159
  • 7
  • 14