Skip to content

Instantly share code, notes, and snippets.

@phpfiddle
Created March 29, 2018 09:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phpfiddle/b1412fb265c97b57aa8f710ba51714f8 to your computer and use it in GitHub Desktop.
Save phpfiddle/b1412fb265c97b57aa8f710ba51714f8 to your computer and use it in GitHub Desktop.
[ Posted by Michaeljpitz ] Multiples of 3 or 5 PHP Codewars
<?php
// Multiples of 3 or 5 PHP
// If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
// Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in.
function solution($number) {
$tot = 0;
for ($i = 3; $i < $number; $i++) if ($i % 3 === 0 || $i % 5 === 0) $tot += $i;
return $tot;
}
echo solution(10);//23
echo "<hr>";
echo solution(20);//...
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment