Php 如何中断/暂停循环X次,然后再次启动相同的循环?
我有一个phpPhp 如何中断/暂停循环X次,然后再次启动相同的循环?,php,while-loop,break,Php,While Loop,Break,我有一个phpwhile循环,它使用sleep(5)函数在5秒内从5发送三个随机数 我想要的是,当第一个循环结束时,我想中断它60秒,然后再次开始相同的循环 $i= 1 do{ $one = mt_rand(1, 99); $two = mt_rand(1, 99); $three = mt_rand(1, 99); $this->SendMessage( 'Number: '.$one.'' ); sleep(5); $this->s
while
循环,它使用sleep(5)
函数在5秒内从5发送三个随机数
我想要的是,当第一个循环结束时,我想中断它60秒,然后再次开始相同的循环
$i= 1
do{
$one = mt_rand(1, 99);
$two = mt_rand(1, 99);
$three = mt_rand(1, 99);
$this->SendMessage( 'Number: '.$one.'' );
sleep(5);
$this->sendMessage( 'Number: '.$two.'' );
sleep(5);
$this->sendMessage( 'Number: '.$three.'' );
sleep(5);
$this->SendMessage( 'The three random numbers has been send, another three numbers will be show in 60 seconds.' );
$i++;
}
while ($i<100);
$i=1
做{
$1=百万兰特(1,99);
$2=百万兰特(1,99);
$3=百万兰特(1,99);
$this->SendMessage('Number:'.$one');
睡眠(5);
$this->sendMessage('Number:'.$two');
睡眠(5);
$this->sendMessage('Number:'.$three');
睡眠(5);
$this->SendMessage('三个随机数已发送,另三个随机数将在60秒内显示');
$i++;
}
虽然($i我想使用可能会成为可能。请参阅PHP手册、示例等。如果我错了,您还可以查看如何执行异步函数调用您是如何启动代码的?它的cli任务还是从浏览器?我在任务中启动代码什么原因,您不想使用睡眠
?因为我想进行一些更新,并且If处于睡眠状态php在这个时候什么也做不了。。