Php implementation code for prime (Prime. Copy the code as follows :? Phpclasstmer {var $ time_start; var $ time_end; function _ construct () {$ this-time_start0; $ this-time_end0;} functiontimer () {$ this-_ constr
The 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 http://www.bkjia.com/PHPjc/323176.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/323176.htmlTechArticle code is as follows :? Php class timer {var $ time_start; var $ time_end; function _ construct () {$ this-time_start = 0; $ this-time_end = 0;} function timer () {$ this-_ constr...