如何在php中强制foreach重置

use*_*827 5 php foreach

有可能在PHP重置foreach?

例如:

foreach($rows as $row)
{
  if(something true)
  {
     continue foreach;
  }
  else
  {
     break;
     reset foreach;//I mean start foreach again...
  }
}
Run Code Online (Sandbox Code Playgroud)

----------------------------------编辑

感谢我的朋友给你的答案......

条件从foreach的结果生成所以我不能使用函数.我在很多DIV html中通过(例如)字母表来调整它.对于相同的共振,我无法通过SQL过滤结果.

所以mybe我必须使用css技巧.

sma*_*sey 5

你可以围绕这些行做一些事情(并避免递归的限制):

while (True) {
    $reset = False;
    foreach ($rows as $row) {
      if(something true) {
         continue;
      } else {
          $reset = True;
          break;
      }
    }
    if ( ! $reset ) {
        break; # break out of the while(true)
    }
    # otherwise the foreach loop is `reset`
}
Run Code Online (Sandbox Code Playgroud)

  • 这非常肮脏,但非常有效。我喜欢它! (3认同)
  • 谢谢......稍微改变一下就用你的简单解决方案为我解决了这个问题。 (2认同)