0

I have an array with multiple arrays within that array and what I want to do is to have the ability to run an array_unique on one of the arrays within my master array, but for every item that array_unique removes, I need it to remove that item from all of the other arrays as well.

For instance:

foreach ($this as $that) {
    $test1[] = $that->testing1;
    $test2[] = $that->testing2;
    $test3[] = $that->testing3;
}
$all = array("Test1" => $test1, "Test2" => $test2, "Test3" => $test3);

So if I want to run an array_unique on $test2 and it removes $test2[4], $test2[7], & $test2[15], then I need it to remove $test1[4], $test3[4], $test1[7], $test3[7], etc.

I'm not exactly sure what the best way to go about doing this is, so I was hoping that someone on here may have an answer since I have found numerous answers here on stackoverflow before. I tried searching everywhere for one, but I think my question is more specific than what I was able to find.

My reasoning behind this is that one of these arrays is loaded with images, but a lot of the images are duplicates, so I want to remove all of the duplicate images. But once I have removed all of the duplicate images, I still have full arrays in the other categories that I don't need any longer.

If you have a better solution to my problem, please let me know. I am really looking for the best solution out there.

zch
  • 14,931
  • 2
  • 41
  • 49
  • Something like `$test1 = &$test2 = &$test3`? It would all point to the same data, so _all_ alterations on `$test1/2/3` would reflect in the other arrays. – Wrikken Sep 23 '13 at 23:28
  • Do you really need 3 separate arrays? why don't you build a single array of objects? – omma2289 Sep 23 '13 at 23:38
  • Actually, I have 10 arrays and they all contain different data about an article. (i.e. Headline, Summary, Image, etc.) I am using arrays only because I know of the array_unique ability. If there is a simpler way to do this, I certainly would be willing to give it a try. – user2808884 Sep 24 '13 at 15:08

0 Answers0