我没有发现我的代码有任何问题,但它只输出 0 到 20 之间的数字,而没有遵循我施加的时间限制。请帮帮我。下面是代码:
<!DOCTYPE html>
<html>
<?php
set_time_limit(0);
class random{
var $max;
var $min;
function irregularnos($min,$max) {
$num = '';
$i = 0;
$this->min=$min;
$this->max=$max;
while($i < 25)
{
$num .= mt_rand($min,$max);
echo $num . "</br>";
$num = '';
$i++;
}
}
}
$rand1 = new random;
$rand2 = new random;
$rand3 = new random;
$rand4 = new random;
date_default_timezone_set('Europe/Berlin');
$start_time = new DateTime(); //current time
while(true){
if ($start_time->modify('+1 seconds')<= new DateTime() and $start_time->modify('+2 seconds') > new DateTime()) { $rand2->irregularnos(21,50);}
else if ($start_time->modify('+2 seconds') <= new DateTime() and $start_time- >modify('+3 seconds') > new DateTime()) { $rand3->irregularnos(51,70);}
else if ($start_time->modify('+3 seconds') <= new DateTime() and $start_time->modify('+4 seconds') > new DateTime()) {$rand4->irregularnos(71,100);}
else if (new DateTime() < $start_time->modify('+1 seconds')) {$rand1->irregularnos(0,20);}
else if(new DateTime()> $start_time->modify('+4 seconds')) { break;}
}
?>