Skip to content

Instantly share code, notes, and snippets.

@davidrautert
Created March 2, 2011 22:33
Show Gist options
  • Save davidrautert/851912 to your computer and use it in GitHub Desktop.
Save davidrautert/851912 to your computer and use it in GitHub Desktop.
Check whether a value or array of values are the only existing values within an array
function in_array_exclusive($needles, $haystack) {
$keys = count($haystack);
if(is_array($needles)) {
foreach($needles as $needle) {
if(!in_array($needle, $haystack)) {
return false;
} else {
$keys = $keys - 1;
}
}
} else {
if(!in_array($needles, $haystack)) {
return false;
} else {
$keys = $keys - 1;
}
}
if($keys == 0) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment