Created
May 19, 2015 21:25
-
-
Save bencarter78/fa1f5d9c0794c5570754 to your computer and use it in GitHub Desktop.
Returns true if the given number is a prime number
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($n) { | |
| $i = 2; | |
| if ($n == 2) { | |
| return true; | |
| } | |
| $sqrtN = sqrt($n); | |
| while ($i <= $sqrtN) { | |
| if ($n % $i == 0) { | |
| return false; | |
| } | |
| $i++; | |
| } | |
| return true; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment