function isPrime($test) {
$prime = 1;
if ($test % 2 == 0 && $test != 2){
return 0;
}
if ($test == 2 || $test == 3) {
return 1;
}
for ($try = 3; $try < $test; $try++){
if (($test % $try) == 0) {
$prime = 0;
}
}
return $prime;
}
Not the most efficient way to do it, but it's simple and gets the job done and returns a 1 or 0 depending on whether the specified number is prime or not.
Enjoy! :)
Edited by Megak, 22 April 2011 - 12:02 PM.


Sign In
Create Account


Back to top









