How to remove duplicate values from a multi-dimensional array in PHP

How to remove duplicate values from a multi-dimensional array in PHP

Whenever you need to remove duplicate values from simple array or multi-dimensional array in PHP and you can follow with given code to get unique values in array.

array_unique() function are used to remove duplicate data from given array. Now question is what value will be removed if there are two or more array values are same, in that scenario it will keep first appearance value in array and removed others.

There are two parameters which will be pass in array_unique(), first specifying an array which is required and second is optioanl specifying sorting type.

Optional parameters sortingtype have possible values :

  • SORT_STRING - Default
  • SORT_NUMERIC
  • SORT_REGULAR
  • SORT_LOCALE_STRING

Remove duplicate values from an array in PHP

Have a look on given example to remove duplicate values from an array.

  1. <?php
  2. $a=array("a"=>"expertphp","b"=>"demo","c"=>"expertphp");
  3. echo "<pre>";
  4. print_r(array_unique($a));
  5. ?>

Output of array before removing duplicate values from a multi-dimensional array in PHP.

  1. Array
  2. (
  3. [a] => expertphp
  4. [b] => demo
  5. [c] => expertphp
  6. )

Output of array after removing duplicate values from an array in PHP.

  1. Array
  2. (
  3. [a] => expertphp
  4. [b] => demo
  5. )

Now you will know how to remove duplicate values from a multi-dimensional array.

Have a look on given example to remove duplicate values from a multi-dimensional array.

  1. <?php
  2. $input=Array(Array('ab','cd'),Array('ef','gh'),Array('ij','kl'),Array('ab','cd'));
  3. echo "<pre>";
  4. print_r($input);
  5. $input = array_map("unserialize", array_unique(array_map("serialize", $input)));
  6. print_r($input);
  7. ?>

Output of array before removing duplicate values from a multi-dimensional array in PHP.

  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [0] => ab
  6. [1] => cd
  7. )
  8. [1] => Array
  9. (
  10. [0] => ef
  11. [1] => gh
  12. )
  13. [2] => Array
  14. (
  15. [0] => ij
  16. [1] => kl
  17. )
  18. [3] => Array
  19. (
  20. [0] => ab
  21. [1] => cd
  22. )
  23. )

Output of array after removing duplicate values from a multi-dimensional array in PHP.

  1. Array
  2. (
  3. [0] => Array
  4. (
  5. [0] => ab
  6. [1] => cd
  7. )
  8. [1] => Array
  9. (
  10. [0] => ef
  11. [1] => gh
  12. )
  13. [2] => Array
  14. (
  15. [0] => ij
  16. [1] => kl
  17. )
  18. )

Find the Duplicate values in array using PHP

  1. <?php
  2. $array=array("expertphp","demo","expertphp");
  3. $count_array = array_count_values($array);
  4. echo "<pre>";
  5. print_r($count_array);
  6. $results = array();
  7. foreach($count_array as $key=>$val){
  8. if($val == 1){
  9. $results[$key] = 'unique';
  10. }
  11. else{
  12. $results[$key] = 'duplicate';
  13. }
  14. }
  15. echo "<pre>";
  16. print_r($results);
  17. ?>

Output :

  1. Array
  2. (
  3. [expertphp] => 2
  4. [demo] => 1
  5. )
  6. Array
  7. (
  8. [expertphp] => duplicate
  9. [demo] => unique
  10. )

Phone: (+91) 8800417876
Noida, 201301
okey metin2 pvp serverler metin2 pvp
ataşehir escort maltepe escort bostancı escort kadıköy escort maltepe escort ataşehir escort tuzla escort pendik escort ümraniye escort kartal escort
pendik escort
izmir escort izmir escort izmir escort izmir escort denizli escort antalya escort antalya escort antalya escort izmir escort izmir escort izmir escort izmir escort izmir escort
hatay escort nevsehir escort nigde escort kirikkale escort batman escort osmaniye escort kirklareli escort tokat escort rize escort adiyaman escort gumushane escort batman escort
cialis satış cialis fiyat cialis 20 mg cialis 100 mg cialis 5 mg fiyat

viagra fiyatı

viagra 100 mg fiyat

viagra sipariş

orjinal viagra

viagra satın al

izmir escort
ataşehir escort
kocaeli escort izmit escort bayan gebze escort izmit sınırsız escort escort bursa tuzla escort aydınlı escort orhanlı escort bursa escort escort bayan istanbul escort istanbul sınırsız escort istanbul bayan escort izmit escort izmit escort kocaeli escort sisli escort mecidiyekoy escort bursa escort bayan bursa görükle escort maltepe escort goztepe escort yakacik-yeni-escort bursa sınırsız escort sisli escort bayan taksim escort bursa escort porno izle sikiş izle atasehir escort antalya escort
ankara escort marmaris escort bursa escort mersin escort antalya escort izmir escort samsun escort bodrum escort çeşme escort kuşadası escort adana escort eskişehir escort gaziantep escort esenyurt escort pendik escort tuzla escort fatih escort ümraniye escort mecidiyeköy escort kartal escort bahçelievler escort bahçeşehir escort ataşehir escort bakırköy escort nişantaşı escort avcılar escort büyükçekmece escort kurtkoy escort konya escort beşiktaş escort taksim escort beylikdüzü escort malatya escort sakarya escort şişli escort maltepe escort kadıköy escort ataköy escort bostancı escort şirinevler escort bağcılar escort üsküdar escort etiler escort başaksehir escort ortaköy escort kağıthane escort sultangazi escort halkalı escort çekmeköy escort şaşkınbakkal escort mamak escort sincan escort keçiören escort çankaya escort beypazarı escort akyurt escort pursaklar escort kahramankazan escort göztepe escort alsancak escort bornova escort buca escort karabaglar escort karşıyaka escort konak escort narlıdere escort izmit escort başiskele escort kandira escort körfez escort karamürsel escort dilovası escort gölcük escort gebze escort kocaeli escort kayseri escort elazığ escort denizli escort diyarbakir escort adana escort ankara escort izmir escort antalya escort gaziantep escort kayseri escort konya escort mersin escort denizli escort kocaeli escort diyarbakır escort
bedava bahis