开发者

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

I have a loop within my script and I need to echo "this is another 100" on each 100th time . For example at 147886900, 147886800, 147886700, 147886600 etc

$account_id_new = 147887000;
while($account_id_new > 2)
{
  //do something开发者_高级运维 
  // echo " this is 100th time";
  $account_id_new = $account_id_new-1;  
}


You can check if $account_id_new is a multiple of 100 by doing this:

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

For more information, see the article on the modulo operator on Wikipedia.


Can you use the modulus operator?

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


is the "do something" part of the code actually doing something? Otherwise, you may just want to decrement by 100 instead of by 1.

Otherwise, try the following

$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;

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜