php,循环(echo从100到100),while


php, loop ( echo from 100 to 100), while

我的脚本中有一个循环,每100次我需要回显"这又是100"。例如,在147886900、147886800、147886700和147886600等

$account_id_new = 147887000;
while($account_id_new > 2)
{
  //do something 
  // echo " this is 100th time";
  $account_id_new = $account_id_new-1;  
}

您可以通过以下操作检查$account_id_new是否为100的倍数:

if ($account_id_new % 100 === 0) {
     echo "100 divides the account id evenly.'n";
}

有关更多信息,请参阅维基百科上关于模运算符的文章。

你能使用模运算符吗?

if ($account_id_new % 100 === 0)
{
    echo '100th time';
}

代码中的"做某事"部分真的在做什么吗?否则,您可能只想递减100而不是1。

否则,请尝试以下

$account_id_new = 147887000;
while($account_id_new > 2) {
    if($account_id % 100 == 0)
       echo " this is 100th time";
$account_id_new = $account_id_new-1;

}