Jump to content

Unique Multidimensional Array


neo115162

Recommended Posts

I have a multidimensional array as follows below:

 

$_ARRAY=array(

array("a"=>"File1.xml","b"=>1111,"c"=>"1"),

array("a"=>"File1.xml","b"=>1111,"c"=>"2"),

array("a"=>"File2.xml","b"=>2222,"c"=>"1"),

array("a"=>"File2.xml","b"=>2222,"c"=>"1"),

array("a"=>"File3.xml","b"=>3333,"c"=>"1"),

array("a"=>"File3.xml","b"=>1111,"c"=>"2")

);

 

As you can tell from above there are 2 duplicates (File1.xml B and C combination is the same as File3.xml B and C combination) and I would like to have a check that shows duplicates with the file name that is associated with those duplicates.

 

Any help is greatly appreciated.

 

Much thanks in advance.

Link to comment
Share on other sites

I can't believe there's not a custom-unique function...weird.

 

This is a handshake problem. A quick and dirty solution to it is:

foreach ( $array as $key => $val ) {
 foreach ( $array as $key2 => $val2 ) {
   if ( $key == $key2 ) continue;
   if ( $val['b'] == $val2['b'] && $val['c'] == $val2['c'] ) {
     //the current pair is a duplicate according to your criteria
   }
 }
}

Note that this is inefficient, for loops would be better, but this is easier to understand.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.