Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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).
- function get_difference ($a,$b)
- {
- $newArray=array();
- foreach($a as $v)
- {
- if(in_array($v,$b))
- {
- }
- else
- {
- $newArray[]=$v;
- }
- foreach($b as $w)
- {
- if(in_array($w,$a))
- {
- }
- else
- {
- $newArray[]=$w;
- }
- }
- }
- return $newArray;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement