-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
  • 115
  • 1
  • 2
  • 8

2 Answers2

3

You must use array_unique() function

$array_unique = array_unique($array);

Results:

    Array
    (
        [0] => 124
        [2] => 35
    )
Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94
user2342558
  • 4,717
  • 5
  • 27
  • 50
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
)
Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94
Léo R.
  • 2,543
  • 1
  • 8
  • 20