Skip to content

Instantly share code, notes, and snippets.

@ak4bento
Created January 15, 2019 05:41
Show Gist options
  • Save ak4bento/22657c945e11790ae590ca1c88e478a4 to your computer and use it in GitHub Desktop.
Save ak4bento/22657c945e11790ae590ca1c88e478a4 to your computer and use it in GitHub Desktop.
implement containLetters function, given two words, returns true if all the letters of the first word are contained in the second.
public function containLetters(string $firstWord, string $secondWord)
{
$result = array();
$inc = 0;
foreach (str_split($firstWord) as $firstSplit)
{
foreach (str_split($secondWord) as $secondSplit)
{
if (strtolower($firstSplit) == strtolower($secondSplit))
{
$result[$inc] = true;
}
else
{
$result[$inc] = false;
}
}
$inc++;
}
foreach ($result as $final)
{
if ($final == false)
{
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment