php 如何将for循环增加1个以上?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19118746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 18:51:13  来源:igfitidea点击:

How to increment a for loop by more than 1?

php

提问by G.d. Venu

How do I print a series like this?

如何打印这样的系列?

6,15,24,33,42.....1000

6,15,24,33,42.....1000

I have tried using a for loop like this, but can't work out how to get it to increment by 9 on each iteration.

我曾尝试使用这样的 for 循环,但无法弄清楚如何在每次迭代中使其增加 9。

for($i = 6; $i <= 1000; $i = 9)
{
    echo $i . ', ';
}

回答by vascowhite

Quite simple really:-

真的很简单:-

for($i = 6; $i <= 1000; $i += 9){
    echo $i . ', ';
}
//If you have to finish the series with 1000, although it is not a part of the series:-
echo '1000';

See it working

看到它工作

回答by arilia

just for fun:

只是为了好玩:

echo implode(', ', range(6, 1000, 9));
echo ", 1000";

回答by nurakantech

<?php
     for($i=6; $i<1000; $i+=9)
      echo $i."<br>";
?>

Seeing the question this can be an answer.

看到这个问题这可以是一个答案。