我有这段代码通过一个数组,其中每个位置都包含一行以前粘贴的文本。我希望 for 循环跳过用户输入的列数的2倍,一旦到达包含单词" Total" 的行。我已经四处寻找,但我找到的只是其他语言的答案。有人可以开导我这个吗?
代码:
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 }
非常感谢。