Last active
November 6, 2015 16:56
-
-
Save kadimi/a58c7c0c778a5d0ecc8e to your computer and use it in GitHub Desktop.
is_prime_number.php
This file contains 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
<?pphp | |
/** | |
* Check if a number is a prime number | |
* @param int $n The number. | |
* @retun boolean True if $n is a prime number, false otherwise. | |
*/ | |
function is_prime_number($n) { | |
$is_prime = true; | |
$max_count = ceil($n/2); | |
for($i=2; $i<$max_count; $i++) { | |
if($n%$i==0) { | |
$is_prime = false; | |
break; | |
} | |
} | |
return $is_prime; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment