Sum

in #ita5 days ago

declare(strict_types=1);

function sumOfMultiples(int $number, array $multiples): int{
$res = 1;
$setres = [];
foreach($multiples as $mult){
if($mult < 1 || $mult > $number) continue;
$i = 1;
while ($res = ($i * $mult) < $number){
$res = $i * $mult;
$setres[] = $res;
$i++;
}
}
$set = array_unique($setres);
return array_sum($set);
}