fork download
  1. <?php
  2. $a_controle = Array('A','B','C','D','E','F');
  3. $array_final = Array(
  4. Array("A","B","C"),
  5. Array("A","B","D"),
  6. Array("A","C","E"),
  7. Array("D","E","F"),
  8. Array("A","B","P")
  9. );
  10.  
  11. $apareceu_com = Array();
  12.  
  13. foreach ($array_final as $sub_array_final){
  14. for ($i = 0; $i < count($sub_array_final); ++$i){
  15. for ($j = 0; $j < count($sub_array_final); ++$j){
  16. $elem1 = $sub_array_final[$i];
  17. $elem2 = $sub_array_final[$j];
  18.  
  19. if ($i != $j){
  20. if (isset($apareceu_com[$elem1][$elem2])){
  21. $apareceu_com[$elem1][$elem2]++;
  22. }
  23. else {
  24. $apareceu_com[$elem1][$elem2] = 1;
  25. }
  26. }
  27. }
  28. }
  29. }
  30.  
  31. print_r($apareceu_com);
Success #stdin #stdout 0.01s 82880KB
stdin
Standard input is empty
stdout
Array
(
    [A] => Array
        (
            [B] => 3
            [C] => 2
            [D] => 1
            [E] => 1
            [P] => 1
        )

    [B] => Array
        (
            [A] => 3
            [C] => 1
            [D] => 1
            [P] => 1
        )

    [C] => Array
        (
            [A] => 2
            [B] => 1
            [E] => 1
        )

    [D] => Array
        (
            [A] => 1
            [B] => 1
            [E] => 1
            [F] => 1
        )

    [E] => Array
        (
            [A] => 1
            [C] => 1
            [D] => 1
            [F] => 1
        )

    [F] => Array
        (
            [D] => 1
            [E] => 1
        )

    [P] => Array
        (
            [A] => 1
            [B] => 1
        )

)