1

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 ?

2
  • 1
    is this data being pulled back from a table using SQL? If so couldn't the problem be addressed there instead? (a la GROUP BY) to only recieve unique responses? Commented Apr 25, 2012 at 12:25
  • 1
    Try using array_unique in php Commented Apr 25, 2012 at 12:26

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

And for reference, array_unique docs
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.

Comments

2

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

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

Hope that helps, Stefan

Comments

0

No array_unique() solution. not so smart:)

array_keys(array_flip($array));

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.