Replaces a series of possible occurrences by a series of substitutes.

@param haystack
@param needle
@param newNeedle
@return
775758
public static String replaceAll(String haystack, String[] needle, String newNeedle[]) {
		if (needle.length != newNeedle.length) {
			throw new IllegalArgumentException("length of original and replace values do not match (" + needle.length + " != " + newNeedle.length + " )");
		}
		StringBuffer buf = new StringBuffer(haystack);
		for (int i = 0; i < needle.length; i++) {
			//TODO not very elegant

			replaceAll(buf, needle[i], newNeedle[i]);
		}
		return buf.toString();
	}
819572
public static function inArrayCaseInsensitive($needle, $haystack)
    {
        if (!$haystack || !is_array($haystack)) {
            return false;
        }
        $lcase = array();
        foreach ($haystack as $key => $val) {
            $lcase[$key] = strtolower($val);
        }
        return in_array(strtolower($needle), $lcase);
    }
569278
public static function array_ikey_exists($needle, $haystack) {
		if (! \is_array($haystack) || ! \count($haystack)) {
			return false;
		}
		$haystack = \array_keys($haystack);

		return (false !== static::array_isearch($needle, $haystack));
	}
96755
public static function wrapSubstr(
        $haystack,
        $needle,
        $wrapEle = null,
        $wrapHaystackOnFailure = false
    ) {
        empty($wrapEle) && $wrapEle = "span";

        if (stripos($haystack, $needle) === false &&
            strtolower(substr($needle, -1)) == 's'
        ) {
            $needle = substr($needle, 0, -1);
        }


        if (stripos($haystack, $needle) !== false) {
            $replace = '<'.$wrapEle.'>$0</'.$wrapEle.'>';

            $return = preg_replace('/'.$needle.'/i', $replace, $haystack);
        }

        if (empty($return)) {
            $return = $haystack;

            if ($wrapHaystackOnFailure) {
                $return = sprintf('<%1$s>%2$s</%1$s>', $wrapEle, $haystack);
            }
        }

        return $return;
    }
917604
def _get_next_occurrence(haystack, offset, needles):
        
        # make map of first char to full needle (only works if all needles
        # have different first characters)
        firstcharmap = dict([(n[0], n) for n in needles])
        firstchars = firstcharmap.keys()
        while offset < len(haystack):
            if haystack[offset] in firstchars:
                possible_needle = firstcharmap[haystack[offset]]
                if haystack[offset:offset + len(possible_needle)] == possible_needle:
                    return offset, possible_needle
            offset += 1
        return None
323441
public static function searchRecursive($needle, $haystack, $needleKey = "", $strict = false, $path = [])
    {
        if (!is_array($haystack)) {

            return false;
        }

        foreach ($haystack as $key => $val) {
            if (is_array($val) &&
                $subPath = self::searchRecursive($needle, $val, $needleKey, $strict, $path)
            ) {
                $path = array_merge($path, [$key], $subPath);

                return $path;
            } elseif ((!$strict && ($val == $needle || is_null($needle)) &&
                    $key == (strlen($needleKey) > 0 ? $needleKey : $key)) ||
                ($strict && $val === $needle &&
                    $key == (strlen($needleKey) > 0 ? $needleKey : $key))
            ) {
                $path[] = $key;

                return $path;
            }
        }

        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;
    }
1360988
public static function unsetInArrayByValue($needle, array $haystack, $reIndex = true)
    {
        $doReindex = false;

        foreach($haystack as $key => $value) {
            if (is_array($value)) {
                $haystack[$key] = static::unsetInArrayByValue($needle, $value);
            } else if ($needle === $value) {

                unset($haystack[$key]);

                if ($reIndex) {
                    $doReindex = true;
                }
            }
        }

        if ($doReindex) {
            $haystack = array_values($haystack);
        }

        return $haystack;
    }
568917
public static function startWith(string $haystack, string $needle): bool
    {
        return ($needle === mb_substr($haystack, 0, mb_strlen($needle, 'UTF-8'), 'UTF-8'));
    }
14261
private function _inArray($needle, $haystack) {
		foreach ($haystack as $strand) {
			if (fnmatch($strand, $needle)) {
				return true;
			}
		}
		return false;
	}
887610
public static function getStartBeforeLast(string $haystack, string $needle)
    {
        $end = self::getEndAfterLast($haystack, $needle);
        $length = -1 * (strlen($end) + strlen($needle));
        return substr($haystack, 0, $length);
    }
310917
public static function substrInArray($needle, array $haystack)
    {
        $filtered = array_filter(
            $haystack,
            function($item) use ($needle) {
                return false !== strpos($item, $needle);
            }
        );

        /** @noinspection IsEmptyFunctionUsageInspection */
        return !empty($filtered);
    }
964037
function trueOrMatch(needle, haystack) {
  if (needle === true) {
    return true;
  }
  if (_.isRegExp(needle) && needle.test(haystack)) {
    return true;
  }
  if (_.isString(needle) && haystack.indexOf(needle) !== -1) {
    return true;
  }
  if (needle instanceof Array) {
    for (var i in needle) {
      if (trueOrMatch(needle[i], haystack)) {
        return true;
      }
    }
  }
  return false;
}
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;
	}
133302
public static function after(
        string $haystack,
        string $needle,
        bool $useLastNeedle = false
    ): string
    {
        $pos = static::getNeedlePosition($haystack, $needle, $useLastNeedle);
        if ($pos === false) {
            return $haystack;
        }
        return substr($haystack, $pos + strlen($needle));
    }
477109
public static function ireplace($needle, $replacement, ?string $haystack): ?string
    {
        if ($haystack === null) {
            return null;
        }

        return str_ireplace($needle, $replacement, $haystack);
    }
981782
public static function getNeedlePositions($haystack, $needle)
    {
        $start = 0;
        $result = array();
        $needleLength = strlen($needle);

        while (($pos = strpos($haystack, $needle, $start)) !== false) {
            $start = $pos + 1;

            // Calculate starting and ending positions
            $startPos = $pos;
            $endPos = $pos + $needleLength;

            // Save them
            $result[$startPos] = $endPos;
        }

        return $result;
    }