Files
codingtests/solutions/other/primesum.php

21 lines
323 B
PHP

<?php
function primeCheck(int $number): bool {
if ($number == 1)
return false;
for ($i = 2; $i <= $number/2; $i++){
if ($number % $i == 0)
return false;
}
return true;
}
$sum = 0;
for($i=2; $i<=1000; $i++)
{
if(primeCheck($i)) {
$sum += $i;
}
}
echo "Sum: $sum\n";