Instantly share code, notes, and snippets.

Embed
What would you like to do?
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