Created
March 2, 2011 22:33
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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