Copy CodeThe code is as follows:
Class Timer
{
var $time _start;
var $time _end;
function __construct ()
{
$this->time_start = 0;
$this->time_end = 0;
}
function timer ()
{
$this->__construct ();
}
function Start ()
{
List ($usec, $sec) = Explode ("", Microtime ());
$this->time_start = (float) $usec + (float) $sec;
}
function Stop ()
{
List ($usec, $sec) = Explode ("", Microtime ());
$this->time_end = (float) $usec + (float) $sec;
}
Function Show ($output = False)
{
$total = $this->time_end-$this->time_start;
if ($output) {
Echo $total, "SEC";
return true;
}
Return $total. "SEC";
}
}
?>
Echo ' Check prime
';
function IsPrime ($i)
{
if ($i <2)
{
return false;
}
var $iterator;
for ($iterator = 2; $iterator <= sqrt ($i); $iterator + +)
{
if ($i% $iterator ==0)
{
return false;
}
}
return true;
}
$SW =new timer ();
$SW->start ();
for ($j =1; $j <100; $j + +)
{
if (IsPrime ($j))
{
Echo ' True
';
}
Else
{
Echo ' false
';
}
}
$SW->stop ();
$SW->show (TRUE);
?>
The above introduces the prime number of what PHP quality (prime number) of the implementation code, including the prime number of what aspects of the content, I hope that the PHP tutorial interested in a friend helpful.