Created
August 20, 2019 08:50
-
-
Save woprrr/8fb60a80d0b0583eec68a99829937ed3 to your computer and use it in GitHub Desktop.
Evaluate if number is prime.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function isPrime(int $number): bool | |
{ | |
$boundary = floor(sqrt($number)); | |
$i = 2; | |
do { | |
if (($number % $i) === 0) { | |
return false; | |
} | |
$i++; | |
} while ($i <= $boundary); | |
return $number >= 2; | |
} | |
$number = 3; | |
var_dump(isPrime($number)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment