Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. Define a function called get_difference, which takes in the same as get_intersection  but it returns a new array that contains all the elements in $a that are not in $b. E.g. if $a is array(2, 5, 1, 7) and $b is array(1, 6, 2, 4), it returns array(5, 7).
  2.  
  3.  
  4. function get_difference ($a,$b)
  5. {
  6.     $newArray=array();
  7.  
  8.     foreach($a as $v)
  9.    
  10.     {
  11.         if(in_array($v,$b))
  12.         {
  13.        
  14.  
  15.         }
  16.         else
  17.         {
  18.             $newArray[]=$v;
  19.  
  20.         }
  21.     foreach($b as $w)
  22.  
  23.     {
  24.         if(in_array($w,$a))
  25.         {
  26.  
  27.  
  28.         }
  29.         else
  30.         {
  31.             $newArray[]=$w;
  32.  
  33.         }
  34.  
  35.  
  36.  
  37.     }
  38.     }
  39.  
  40.  
  41.     return $newArray;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement