-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
        )
Mahdi98
  • 135
  • 1
  • 2
  • 8

2 Answers2

3

You must use array_unique() function

$array_unique = array_unique($array);

Results:

    Array
    (
        [0] => 124
        [2] => 35
    )
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
user2342558
  • 5,567
  • 5
  • 33
  • 54
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
)
Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Léo R.
  • 2,620
  • 1
  • 10
  • 22