fork download
  1. <?php
  2. $a = [1,2,3,4,5];
  3. $b = [1,3,5,6,7,5,3];
  4.  
  5. $iguais = [];
  6. $diferentes = [];
  7. foreach($a as $item){
  8. $i = array_search($item, $b);
  9. if($i !== false){
  10. $iguais[] = '('. $item .', '. $b[$i] .')';
  11. unset($b[$i]);
  12. }else{
  13. $diferentes[] = $item;
  14. }
  15. }
  16.  
  17. $diferentes += $b;
  18.  
  19. echo "<pre>";
  20. print_r($iguais);
  21.  
  22. echo "<pre>";
  23. print_r($diferentes);
Success #stdin #stdout 0.03s 52480KB
stdin
Standard input is empty
stdout
<pre>Array
(
    [0] => (1, 1)
    [1] => (3, 3)
    [2] => (5, 5)
)
<pre>Array
(
    [0] => 2
    [1] => 4
    [3] => 6
    [4] => 7
    [5] => 5
    [6] => 3
)