php_pimebday/index.php

31 lines
611 B
PHP
Raw Normal View History

2024-01-16 17:23:38 +01:00
<?php
function getNextPrimeBdays(int $age, int $countNextBdays,?int $ageLimit = null):array{
if ($ageLimit === null){
$ageLimit = 100;
}
$out = [];
while($countNextBdays > 0) {
for ($age = 32; $age <= $ageLimit; $age++) {
$primenum = true;
for($denominator = 2; $denominator <= $age/2; $denominator++) {
if(((float)$age % (float)$denominator) == 0.0) {
$primenum = false;
break;
}
}
if ((bool)$primenum) {
$out[] = $age;
$countNextBdays--;
if($countNextBdays == 0){
break;
}
}
}
}
return $out;
}
echo json_encode(getNextPrimeBdays(32,10));