Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force foreach reset in php

Tags:

foreach

php

Is possible in php to reset The foreach?

for example:

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

----------------------------------Edited

Thanks my friend for your answers...

The condition generate from result of foreach so I can not use function. I wana sortet it by (fro example) alphabet...in many DIV html. I can not filter result by SQL for same reson.

So mybe I have to use a css trick.

like image 268
user3307827 Avatar asked Mar 03 '14 15:03

user3307827


1 Answers

You could do something around these lines (and avoid the limitations of recursion):

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`
}
like image 97
smassey Avatar answered Nov 14 '22 23:11

smassey