Location: PHPKode > scripts > Math prime 4.0 or higher > math-prime-4-0-or-higher/math_prime.php
```<?php
/*
_____                    ______ _   _ ______
|  __ \                   | ___ \ | | || ___ \
| |  \/_ __ ___  ___ _ __ | |_/ / |_| || |_/ /
| | __| '__/ _ \/ _ \ '_ \|  __/|  _  ||  __/
| |_\ \ | |  __/  __/ | | | |   | | | || |
\____/_|  \___|\___|_| |_\_|   \_| |_/\_|
----------------------------------------------
(C)BOBAK 2008                             V4.0
----------------------------------------------
web   : http://www.greenphp.com
----------------------------------------------
*/

/**
* Check a number if prime
*
* @author Bobak
* @package math
* @subpackage prime
*/

class math_prime
{

public static function test(\$Number)
{
//No prime as def
\$Out=FALSE;

//First primes def
\$FirsPrimes=array(1=>TRUE,2=>TRUE,3=>TRUE,5=>TRUE,7=>TRUE);

//Numeric & INT
if (is_integer(\$Number))
{
//First primes test
if (isset(\$FirsPrimes[\$Number]))
{\$Out=TRUE;}
//Symetrie test 1,3,5,7,9 (but 5 is too)
elseif (\$Number%2 AND \$Number%3 AND \$Number%5 AND \$Number%7)
{
// Is prime as def
\$Out=TRUE;

// a*a=b then min prime of b is a
\$Loop=floor(sqrt(\$Number));

//Fires primes tested
if (\$Loop>10)
{
while (\$Loop>10)
{
//No prime
if ((\$Number%\$Loop)==0)
{
\$Out=FALSE;
break;
}
//Next test of 1,3,5,7,9 (but 5 is too)
\$Loop-=2;
}
}
}
}

return \$Out;
}
}
?>```