From f44fd251e10706de3a72fa49739e415fe66edecf Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Wed, 5 Aug 2020 09:06:28 +0200 Subject: [PATCH] Add functions startsWithAny, startsWith --- MD_STD.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/MD_STD.php b/MD_STD.php index 95be7ef..eeeba8a 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -51,4 +51,38 @@ class MD_STD { } + /** + * Function checking if a string starts with another. + * + * @param string $haystack String to check. + * @param string $needle Potential start of $haystack. + * + * @return boolean + */ + public static function startsWith(string $haystack, string $needle):bool { + + if (substr($haystack, 0, strlen($needle)) == $needle) return true; + else return false; + + } + + /** + * Function checking if a string starts with any input from the input array. + * + * @param string $haystack String to check. + * @param string[] $needles Array containing potential start values of $haystack. + * + * @return boolean + */ + public static function startsWithAny(string $haystack, array $needles):bool { + + $output = false; + foreach ($needles as $needle) { + $output = self::startsWith($haystack, $needle); + if ($output == true) return $output; + } + return $output; + + } + }