Created
December 30, 2018 03:13
-
-
Save lablnet/51846acefb2f4b3c49e34dbecad1ec4f to your computer and use it in GitHub Desktop.
Determine whether the given number is prime or not
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
<?php | |
function isPrime($n) | |
{ | |
for ($i = 2; $i < $n ; $i++) { | |
if ($n % $i === 0){ | |
return false; | |
} | |
} | |
return true; | |
} | |
//Usage | |
var_dump(isPrime(9)); // bool(false) | |
var_dump(isPrime(11)); // bool(true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment