Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created September 18, 2010 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xeoncross/586042 to your computer and use it in GitHub Desktop.
Save xeoncross/586042 to your computer and use it in GitHub Desktop.
<?php
$array_1 = array('zero', 'two', 'three', 'five');
$array_2 = array('one', 'three', 'four','six','eight', 'nine');
$array_3 = array('one', 'four', 'five', 'six','seven', 'eight');
$array_4 = array('zero', 'four', 'five', 'eight', 'nine');
// All elements missing from one array that are present in the other
function array_diff2($a,$b)
{
return array_diff(array_merge($a,$b),array_intersect($a,$b));
}
// Elements missing from $a, that are present in every other array
function array_missing($a,$b,$c ='$d,$e,etc..')
{
$a=array_diff($b,$a);foreach(array_slice(func_get_args(),2)as$c)$a=array_intersect($a,$c);return$a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment