Skip to content

Instantly share code, notes, and snippets.

@iCaspar
Created November 15, 2018 02:36
Show Gist options
  • Save iCaspar/7becd5b72568b6dc0fb390282b8bb2fe to your computer and use it in GitHub Desktop.
Save iCaspar/7becd5b72568b6dc0fb390282b8bb2fe to your computer and use it in GitHub Desktop.
Has 5s recursive method to find numbers with 5s in them.
/**
* Does this number have 5s?
*
* @param $number Number to check.
*
* @since 1.0.0
*
* @return bool
*/
private function hasFive($number): bool
{
$number = abs($number);
while ($number) {
if ($number % 10 == 5) {
return true;
}
$number = floor($number / 10);
return $this->hasFive($number);
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment