Find all the positions of a needle in a haystack string
@param  {string} needle   string to find
@param  {string} haystack string to scan
@return {Array}  Either -1 if no match is found or an array containing the indicies
426761
function findAllIndices() {
  var needle = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : mandatory();
  var haystack = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mandatory();

  var indices = [];
  for (var i = 0; i < haystack.length; i++) {
    if (haystack.substr(i, needle.length) === needle) {
      indices.push(i);
    }
  }

  if (indices.length) {
    return indices;
  } else {
    return -1;
  }
}
187255
protected function string_contains( $haystack, $needles ) {
		foreach ( (array) $needles as $needle ) {
			if ( '' !== $needle && mb_strpos( $haystack, $needle ) !== false ) {
				return true;
			}
		}

		return false;
	}
615791
private function findAddress($needle, array $haystack)
    {
        $address = $this->justAddress($needle);
        foreach ($haystack as $i => $item) {
            if ($this->justAddress($item) == $address) {
                return $i;
            }
        }

        return false;
    }
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;
    }
1290454
function in_array( needle, haystack )
	{
		var found = 0,
			key;
		for ( key in haystack )
		{
			if ( haystack[ key ] == needle )
			{
				found = 1;
				break;
			}
		}
		return found;
	}
991230
public function match($needle, $haystack)
    {
        $len = strlen($needle);

        /** @noinspection SubStrUsedAsStrPosInspection */
        return $len === 0 || substr($haystack, 0, $len) === $needle;
    }
1344326
private function index_of($haystack, $needle, $offset = 0)
    {
        $index = strpos($haystack, $needle, $offset);

        return ($index !== FALSE) ? $index : -1;
    }
425963
function (needle, haystack) {
            needle.width = needle.width || 0;
            needle.height = needle.height || 0;
            if (haystack == this.VIEWPORT) {
                return this.isInViewport({
                    left : needle.x,
                    top : needle.y
                }, {
                    width : needle.width,
                    height : needle.height
                });
            }
            haystack.width = haystack.width || 0;
            haystack.height = haystack.height || 0;
            if (needle.x < haystack.x || needle.y < haystack.y || needle.x + needle.width > haystack.x + haystack.width
                    || needle.y + needle.height > haystack.y + haystack.height) {
                return false;
            }
            return true;
        }
927228
function beginsWith(haystack, needles) {
    let needle;
    for (let i = 0, u = needles.length; i < u; ++i) {
        needle = needles[i];
        if (haystack.substr(0, needle.length) === needle) {
            return true;
        }
    }
    return false;
}
892547
public static void replaceFirst(StringBuffer haystack, String needle, String newNeedle) {
		int idx = haystack.indexOf(needle);
		if (idx != -1) {
			haystack.replace(idx, idx + needle.length(), newNeedle);
		}
	}
1291942
public static function words_match($haystack, $needle)
    {
        $a_needle  = self::tokenize_string($needle, 1);
        $_haystack = join(" ", self::tokenize_string($haystack, 1));
        $valid     = strlen($_haystack) > 0;
        $hits      = 0;

        foreach ($a_needle as $w) {
            if ($valid) {
                if (stripos($_haystack, $w) !== false) {
                    $hits++;
                }
            }
            else if (stripos($haystack, $w) !== false) {
                $hits++;
            }
        }

        return $hits >= count($a_needle);
    }
797729
public static <T> boolean contains(T needle, T...hayStack)
	{
		if(needle == null)
			return containsNull(hayStack);
		if(hayStack == null)
			return false;
		for(T hay : hayStack)
			if(needle.equals(hay))
				return true;
		return false;
	}
1219199
private function strlikeInArray($needle, array $haystack):bool
    {
        foreach ($haystack as $one => $value) {
            if (preg_match("/$value/", $needle) === 1) {
                return (true);
            }
        }
        return (false);
    }
824997
def contains(haystack, needle):
    
    if sys.version_info[0] < 3:
        return needle in haystack
    else:
        return to_bytes(needle) in to_bytes(haystack)
1156820
public static function strContains($needles, $haystack)
    {
        if (!is_array($needles)) {
            $needles = (array) $needles;
        }

        foreach ($needles as $needle) {
            if (strpos($haystack, $needle) !== false) {
                return true;
            }
        }

        return false;
    }
1191725
public static function within( $haystack, $needle, $offset = 0, $caseSensitive = false )
    {
        if ( false === $caseSensitive )
        {
            //	Case-insensitive
            return false !== stripos( $haystack, $needle, $offset );
        }

        //	Case-sensitive
        return false !== strpos( $haystack, $needle, $offset );
    }
749658
public static function recursiveArraySearch($needle, $haystack)
    {
        foreach ($haystack as $key => $value) {
            $current_key = $key;
            if ($needle === $value or (is_array($value) && self::recursiveArraySearch($needle, $value) !== false)) {
                return $current_key;
            }
        }
        return false;
    }