0

I have all several files that contain the data I collected this data as a two-dimensional array now I must veriefie there is data in the file (file1) and if they redandante in other files :means (i have transforemed my files to array) for example tab [0] [j] with another tab [ i][j] except intersection with him self (i! = 0) tab[0][0]="a"; tab[0][1]="b"; tab[0][2]="ac"; tab[0][3]="n"; tab[1][0]="g"; tab[1][1]="a"; tab[1][2]="h"; tab[1][3]="b"; tab[2][0]="gdd"; tab[2][1]="a"; tab[2][2]="hd"; tab[2][3]="b"; my program must allow me to compare always tab[0][] with others I hope that I'm clear this time and thanks for your help

natalie
  • 1
  • 2
  • Please see [Is English required on Stack Overflow?](http://meta.stackexchange.com/questions/13676/is-english-required-on-stack-overflow/13684#13684) – Quentin Apr 08 '13 at 09:18
  • http://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php – Marko D Apr 08 '13 at 09:20
  • Please give examples of your array, and what you want after eliminating the duplicates – Mark Baker Apr 08 '13 at 09:51
  • tab [0] [0] = 'a', tab [0] [1] = b, tab [0] [2] = s, ... onglet [1] [0] = d, onglet [1] [ 1] = a, ... onglet [2] [0] = a, onglet [2] [1] = g, ... voila un exemple de mon tableau – natalie Apr 08 '13 at 11:22
  • someone has an idea how to proceed!!! :( – natalie Apr 08 '13 at 12:20
  • my problem is not like: http://stackoverflow.com/questions/307674/how-to-remove-duplicate-values-from-a-multi-dimensional-array-in-php – natalie Apr 08 '13 at 12:36
  • My array is in two dimensions; I want to compare one subarray (that is the same, it is invariable) with other subarrays – natalie Apr 08 '13 at 12:39
  • I have proceeded like this but without success: or($i=0; $i<$nb; $i++) { for($j=0;$j – natalie Apr 08 '13 at 13:58

1 Answers1

0
$withDuplicates = array(
    array(1,2,3,4),
    array(1,3,2,4),
    array(1,2,3,5),
    array(1,3,2,4),
    array(1,2,3,4),
);

$duplicatesEliminated = array_map(
    'unserialize',
    array_reduce(
        $withDuplicates,
        function ($returnArray, $entry) {
            $serialized = serialize($entry);
            if (!in_array($serialized, $returnArray))
                $returnArray[] = $serialized;
            return $returnArray;
        },
        array()
    )
);

var_dump($duplicatesEliminated);
Mark Baker
  • 209,507
  • 32
  • 346
  • 385