-3

I have following associative array I wanna remove those ones that which have same value and keep one of theme(for example there is tow 124 value one of theme should be removed):

Array
        (
            [0] => 124
            [1] => 124
            [2] => 35
        )
2
  • How is your array associative? Commented Jan 22, 2018 at 16:34
  • This doesn't look like an associative array, it looks like an indexed array. Commented Jan 22, 2018 at 16:34

2 Answers 2

3

You must use array_unique() function

$array_unique = array_unique($array);

Results:

    Array
    (
        [0] => 124
        [2] => 35
    )
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the array_unique() method

For example :

<?php
$input = array("a" => "green", "red", "b" => "green", "blue", "red");
$result = array_unique($input);
print_r($result);
?>

Output :

Array
(
    [a] => green
    [0] => red
    [1] => blue
)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.