mirror of
https://github.com/TheAlgorithms/PHP.git
synced 2025-01-17 15:18:13 +01:00
23 lines
323 B
PHP
23 lines
323 B
PHP
|
<?php
|
||
|
|
||
|
function isPrime(int $number)
|
||
|
{
|
||
|
if ($number === 2) {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
if ($number % 2 === 0 or $number < 2) {
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
$i = 3;
|
||
|
while ($i < sqrt($number)) {
|
||
|
if ($number % $i === 0) {
|
||
|
return false;
|
||
|
}
|
||
|
$i += 2;
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|