• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 600
  • Last Modified:

Removing Duplicate Keys from Multiple Arrays

array_unique can be used to remove duplicate key value sets from an array.

How do I remove duplicate key values sets by comparing multiple arrays?
0
deharvy
Asked:
deharvy
  • 3
1 Solution
 
Pratima PharandeCommented:
try

$arr = array_map('unserialize', array_unique(array_map('serialize', $arr)));

refer
http://stackoverflow.com/questions/1247950/how-to-remove-duplicated-2-dimension-array-in-php
0
 
Ray PaseurCommented:
Give us some example inputs and expected outputs.  It matters whether the array keys are numeric or associative.
0
 
Ray PaseurCommented:
The exact definition of "remove" also matters.  Do you want to eliminate duplicates from all of the arrays?  Or do you want to keep only one copy in one of the arrays?  Do you want to test for duplicate keys, or duplicate values or duplicate key=>value pairs?  
0
 
deharvyAuthor Commented:
Ray,

I only want to test for duplicate values. The key doesn't matter.

So, when I do a print_r, it should only display one key with a unique value.

Hope this is more clear.
0
 
Ray PaseurCommented:
Please give us some example inputs and expected outputs, thanks.  Like how many arrays are involved, and whether the keys are associative or numeric?  Thanks, ~Ray
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now