doulan8846 2018-06-08 09:14
浏览 55

PHP - 跳过多个for循环迭代

I have this piece of code that goes through an array where each position contains a line of previously pasted text. I want the for loop to skip 2 times the number of columns input by the user, once it reaches a line that contains the word "Total". I've searched around but all I found were answers for other languages. Can anybody enlighten me on this?

Code:

1 $j = -1;
2 $step = 1;
3 for($i = 0; $i < count($statisticsinput); $i++){
4   if(strpos($statisticsinput[$i], "Total") !== false){
5      $i += 2*$_POST['columno']; //Trying to make the counter skip the 2*col iterations but seems to have no effect
6      if($step !== 2){ //The word Total appears 2 times in the pasted text, the first time
7        $step++;      //should keep the script going but not the second one
8       }else{
9         break;
10      }
11      continue; //After incrementing the counter 2*col, skip over the next steps and 
12   }           //go to the next loop. I expected it to jump 2*col loops (usually 22)
13   if($i % $_POST['columno'] == 0){
14      $j++;
15   }
16   $employees[$j][] = $statisticsinput[$i];
17 }

Many thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值