public static isIn ( mixed $needle, array | Traversable $haystack, boolean $strict = false ) : boolean | ||
$needle | mixed | The value to look for. |
$haystack | array | Traversable | The set of values to search. |
$strict | boolean | Whether to enable strict (`===`) comparison. |
return | boolean | `true` if `$needle` was found in `$haystack`, `false` otherwise. |
public static function isIn($needle, $haystack, $strict = false)
{
if ($haystack instanceof \Traversable) {
foreach ($haystack as $value) {
if ($needle == $value && (!$strict || $needle === $value)) {
return true;
}
}
} elseif (is_array($haystack)) {
return in_array($needle, $haystack, $strict);
} else {
throw new InvalidParamException('Argument $haystack must be an array or implement Traversable');
}
return false;
}