title: is there a way in PHP to restart a loop in a foreach, or change the test value in a switch?
body: <p>if i'm looping over an array, and while in the middle of one of the loops i discover some small issue, change ...something..., and need to try again ... is there a way to jump back to the top of the loop without grabbing the next value out of the array?</p>
  
  <p>i doubt this exists, but it would be some keyword like <code>continue</code> or <code>break</code>. in fact, it would be a lot like <code>continue</code>, except that it doesn't get the next item, it maintains what it has in memory.</p>
  
  <p>if nothing exists, can i insert something into the array in such a way that it will become the next key/value in the loop?</p>
  
  <p>maybe this would be easier with a while(array_shift())...</p>
  
  <p>or i suppose a recursive function inside the loop might work.</p>
  
  <p>well, my question is evolving as i type this, so please review this pseudo code:</p>
  
  <pre><code>foreach($storage_locations as $storage_location) {
      switch($storage_location){
          case 'cookie':
              if(headers_sent()) {
                  // cannot store in cookie, failover to session
                  // what can i do here to run the code in the next case?
                  // append 'session' to $storage_locations?
                  // that would make it run, but other items in the array would run first... how can i get it next?
              } else {
                  set_cookie();
                  return;
              }
          break;
  
          case 'session':
              set_session();
              return;
          break;
      }
  }
  </code></pre>
  
  <p>i'm sure there is no keyword to change the value tested against in the switch mid-stream... so how should i refactor this code to get my failover?</p>