title: PHP nested foreach loop iterate and set variable
body: <p>I got a problem with my variable within a nested foreach loop in php:</p>
  
  <p>My variable $counter doesn't reset to 1 after the inner loop is done. I also tried to unset($co
  unter) after the inner loop, which didn't have any effect either. I am aware that there is no inner scope in foreach loops in php. But I thought, once I set the $counter=1 after the inner loop is done, then the next outer loop and with it the new inner loop should start with $counter=1 again??</p>
  
  <pre><code>&lt;?php
  $counter = 1;
  foreach($loop1 as $x){
  
       foreach($loop2 as $y){  
         if($counter==1){do something};
  
         else {do something else};           
         $counter++;
        };
   $counter = 1;
  
   }    
  
  ?&gt;
  </code></pre>
  
  <p>This is the actual code:</p>
  
  <pre><code>&lt;?php
  $i=1;
  foreach ($neu as $n) {
      $gcount = 1;
  
  
      echo'&lt;div&gt; &lt;/div&gt;';
  
  
  
  
      foreach ($gesendet as $g) {
          if (($n["Quelle"] ==$g["Quelle"]) || ($n["Quelle"] ==$g["Ziel"])){
  
                  if ($gcount == 1){
                  echo nl2br("\n");                   
              }
  
              else {
                  echo'&lt;div id="divtoggle"&gt;' .nl2br("\n")."at ".$g['Datum']." ".  htmlspecialchars($g['username']). nl2br(" wrote: \n") ;  
                  echo "\"".htmlspecialchars($g['Inhalt']). "\"" .nl2br("\n");    
                  echo '&lt;/div&gt;';                  
              }
      }
      $gcount++;
      }
      unset($gcount);
      echo '&lt;/div&gt;';          
       $i++;  
  }
  
  ?&gt;
  </code></pre>