Search an array for multiple values.

@param array $needles
the values to search the `$haystack` for.
@param array $haystack
the in which to search for the `$needles`
@return boolean
true if any of the `$needles` are in `$haystack`,
false otherwise.
5987
public static function in_array_all($needles, $haystack)
    {
        foreach ($needles as $n) {
            if (!in_array($n, $haystack)) {
                return false;
            }
        }

        return true;
    }
138235
public static function contains($haystack, $needle)
    {
        foreach ((array)$needle as $n) {
            if (strpos($haystack, $n) !== false) {
                return true;
            }
        }

        return false;
    }
1316621
public static function endsWith($haystack, $needles)
    {
        foreach ((array) $needles as $needle) {
            if (substr($haystack, -strlen($needle)) === (string) $needle) {
                return true;
            }
        }

        return false;
    }
1340777
public static function contains( $haystack, $needles )
    {
        foreach ( ( array ) $needles as $needle )
        {
            if ( '' !== $needle && FALSE !== strpos( $haystack, $needle ) )
            {
                return TRUE;
            }
        }

        return FALSE;
    }
1332507
public static function collectionContains($needle, $haystack)
    {
        foreach ($haystack as $value) {
            if ($value === $needle) {
                return true;
            }
        }

        return false;
    }
1239455
public function in_multiarray($needle, $haystack)
    {
        foreach ($haystack as $value) {
            if (is_array($value)) {
                if ($this->in_multiarray($needle, $value)) {
                    return true;
                }
            } else {
                if ($value == $needle) {
                    return true;
                }
            }
        }
        return false;
    }
483320
public static function contains($haystack, $needle)
    {
        if (1 === strlen($needle) && !self::isLetterOrDigit($needle)) {
            $needle = '\\' . $needle;
        }

        return (bool)preg_match('|.*' . $needle . '.*|', $haystack);
    }
550576
public static function recursivelySetValue($needleKey, $needleValue,
                                               array &$haystack)
    {
        foreach ($haystack as $key => &$value) {
            if (isset($haystack[$needleKey])) {
                $haystack[$needleKey] = $needleValue;
            }

            if (is_array($value)) {
                self::recursivelySetValue($needleKey, $needleValue, $value);
            }
        }
    }
617236
public function containsValues(array $needles): bool
    {
        return \count(\array_intersect($needles, $this->getArray()), \COUNT_NORMAL)
               ===
               \count($needles, \COUNT_NORMAL);
    }
189897
public static function contains($haystack, $needles)
    {
        foreach ((array) $needles as $needle) {
            if ($needle !== '' && mb_strpos($haystack, $needle) !== false) {
                return true;
            }
        }

        return false;
    }
580397
public static function search(array $haystack, $needle)
    {
        foreach ($haystack as $key => $value) {
            if (is_array($value)) {
                $target = self::search($value, $needle); 
            } else {
                $target = '';
            }

            if ($needle === $value || ($target != false && $target != null)) {
                if ($target == null) {
                    return array($key);
                }
                return array_merge(array($key), $target);
            }
        }

        return false;
    }
1328700
public function containsAny($needles): bool
    {
        $needlesBag = $this->transformToBag($needles);

        return !!array_intersect($needlesBag, $this->bag);
    }
351773
public static function iin_array($needle, $haystack, bool $strict=true) {
		return (false !== static::array_isearch($needle, $haystack, $strict));
	}
3536
protected function inArray(array $needle, array $haystack) {
        // Loop over all the values in the needle array, and make sure each and every one is in some
        // way present in the haystack, in a recursive manner.
        foreach ($needle as $needleValue) {
            if (is_array($needleValue)) {
                // If the value is an array we need to do a recursive compare / inArray check
                if ($this->arrayIsList($needleValue)) {
                    // The needle value is a list, so we only want to compare it to lists in the
                    // haystack
                    $listElementsInHaystack = array_filter($haystack, function($element) {
                        return is_array($element) && $this->arrayIsList($element);
                    });

                    if (empty($listElementsInHaystack)) {
                        throw new ArrayContainsComparatorException(
                            'Haystack does not contain any list elements, needle can\'t be found.', 0, null,
                            $needleValue, $haystack
                        );
                    }

                    $result = array_filter($listElementsInHaystack, function ($haystackListElement) use ($needleValue) {
                        try {
                            return $this->inArray($needleValue, $haystackListElement);
                        } catch (ArrayContainsComparatorException $e) {
                            // If any error occurs, swallow it and return false to mark this as a
                            // failure
                            return false;
                        }
                    });

                    // Result is empty, which means the needle was not found in the haystack
                    if (empty($result)) {
                        throw new ArrayContainsComparatorException(
                            'The list in needle was not found in the list elements in the haystack.', 0, null,
                            $needleValue, $haystack
                        );
                    }
                } else {
                    // The needle value is an object, so we only want to compare it to objects in
                    // the haystack
                    $objectElementsInHaystack = array_filter($haystack, function($element) {
                        return is_array($element) && $this->arrayIsObject($element);
                    });

                    if (empty($objectElementsInHaystack)) {
                        throw new ArrayContainsComparatorException(
                            'Haystack does not contain any object elements, needle can\'t be found.', 0, null,
                            $needleValue, $haystack
                        );
                    }

                    $result = array_filter($objectElementsInHaystack, function ($haystackObjectElement) use ($needleValue) {
                        try {
                            return $this->compare($needleValue, $haystackObjectElement);
                        } catch (ArrayContainsComparatorException $e) {
                            // If any error occurs, swallow it and return false to mark this as a
                            // failure
                            return false;
                        }
                    });

                    // Result is empty, which means the needle was not found in the haystack
                    if (empty($result)) {
                        throw new ArrayContainsComparatorException(
                            'The object in needle was not found in the object elements in the haystack.', 0, null,
                            $needleValue, $haystack
                        );
                    }
                }
            } else {
                $result = array_map(function($haystackElement) use ($needleValue) {
                    return $this->compareValues($needleValue, $haystackElement);
                }, $haystack);

                if (empty(array_filter($result))) {
                    throw new ArrayContainsComparatorException(
                        'Needle is not present in the haystack.', 0, null,
                        $needleValue, $haystack
                    );
                }
            }
        }

        // All's right with the world!
        return true;
    }
1192826
public function containsKeys(array $needles, $recursive = false): bool
    {
        if ($recursive === true) {
            return \count(
                       \array_intersect($needles, $this->keys(true)->getArray()),
                       \COUNT_RECURSIVE
                   )
                   ===
                   \count(
                       $needles,
                       \COUNT_RECURSIVE
                   );
        }

        return \count(
                   \array_intersect($needles, $this->keys()->getArray()),
                   \COUNT_NORMAL
               )
               ===
               \count(
                   $needles,
                   \COUNT_NORMAL
               );
    }
1003507
public static function contains(string $haystack, string $needle, int $offset = 0): bool
    {
        return self::strpos($haystack, $needle, $offset) !== false;
    }
732173
public static function searchKey($array, $needle)
    {
        $return = false;
        if (!\is_array($array)) {
            $array = array();
        }
        $arrayKeys = array();
        foreach ($array as $k => $v) {
            if ($k == $needle) {
                $return = $v;
                break;
            }
            if (\is_array($v)) {
                // don't search deeper levels until finished with this level
                $arrayKeys[] = $k;
            }
        }
        if ($return === false) {
            foreach ($arrayKeys as $k) {
                $result = self::searchKey($array[$k], $needle);
                if ($result !== false) {
                    $return = $result;
                    break;
                }
            }
        }
        return $return;
    }