1

I want to show data in array all but except the ones that are duplicates.

My array looks like this:

array (size=4)
       0 => string 'Eclairage Public' (length=16)
       1 => string 'Fonte de Voirie' (length=15)
       2 => string 'Aire de jeux' (length=12)
       3 => string 'Aire de jeux' (length=12)
       4 => string 'Fonte de Voirie' (length=15)

I want it to show only:

array (size=4)
       0 => string 'Eclairage Public' (length=16)
       1 => string 'Fonte de Voirie' (length=15)
       2 => string 'Aire de jeux' (length=12)

As you can see, the duplicate elements were removed. How can I accomplish this using PHP?

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
koe
  • 736
  • 1
  • 12
  • 33

2 Answers2

1

use array_unique(). It removes duplicate values from an array.

$arr = array_unique($arr);
Brandon
  • 16,382
  • 12
  • 55
  • 88
Nambi
  • 11,944
  • 3
  • 37
  • 49
  • Hasn't this already been answered *a lot* of times before? I don't think there's a need to answer every such question with "use `array_unique()`". The right thing to do would've been to close-vote the question as a duplicate (since you now have the CV privileges). – Amal Murali Feb 22 '14 at 03:41
  • @AmalMurali IMO, both are appropriate. Answering the question and marking it as a duplicate. – Brandon Feb 22 '14 at 03:42
  • 1
    @BrandonWamboldt: No, there's no need to answer obvious duplicates, vote for closure instead. See [this Meta thread](http://meta.stackexchange.com/a/10844/). – Amal Murali Feb 22 '14 at 03:45
  • @AmalMurali Cool, thanks for the link. I'll keep that in mind going forward :) – Brandon Feb 22 '14 at 03:46
  • It's work well thank you too much . – koe Feb 22 '14 at 04:08
0

array_unique is what you looking for.

$array = array_unique($array);
Brandon
  • 16,382
  • 12
  • 55
  • 88
Faiz Shukri
  • 95
  • 10