douchen4915 2019-06-14 08:09
浏览 164
已采纳

如何在PHP中循环几个数字?

I have a question to looping several numbers together.

I've tried to do with two function below:

for ($x=28; $x <= 31; $x++){
    echo $x.'<br>';
}

for($i=1; $i<6; $i++){
    echo $i.'<br>';
}

But I want the script with a single step like:

for(){
  // code
  for(){
     // code
  }
}

And the final result, I try to implement it on the input option:

<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
  • 写回答

3条回答 默认 最新

  • dqv2743 2019-06-14 09:20
    关注

    Hi if need to print only

    `<option>28</option>`
        <option>29</option>
        <option>30</option>
        <option>31</option>
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
    
    then can use below code 
    $start = 28;
    $count = 31;
    
    for ($x = $start; $x <=$count; $x++){
           echo '<option>'.$x.'</option>';
    
        if($x==31){
            $count=6;
             $x=0;
    
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题