title: Strange behavior in foreach loop over multidimensional array
body: <p><strong>THE QUESTION</strong></p>
  
  <p>Why is the line with <code>"l++;"</code> impacting the loop counts of the foreach loop? That line is merely there as a counter but somehow it is impacting the end result.</p>
  
  <p>Can someone please help explain what is going on here?</p>
  
  <p><strong>THE CODE</strong></p>
  
  <p>I have the following multidimensional array:</p>
  
  <pre><code>$team_array = array(
      array(68, 6, 0, 10, "1.000"),
      array(72, 6, 0, 10, "1.000"),
      array(65, 6, 0, 8, "1.000"),
      array(62, 6, 0, 4, "1.000"),
      array(54, 3, 3, 3, ".500"),
      array(55, 3, 3, -5, ".500"),
      array(59, 0, 6, -16, ".000")
  );
  </code></pre>
  
  <p>I am using the following code to loop over the arrays. </p>
  
  <pre><code>$foo = "1.000";    
  $k = 0;
  $l = 0;
  $m = 0;
  $n = 0;
  foreach($team_array as $index =&gt; $inner_arr)
  {
      foreach($inner_arr as $value)
      //echo $value.", ";
      //echo "&lt;br/&gt;";
      $l++;
      { 
          $m++;
          echo "index - $index&lt;br&gt;";
          echo "perc = ".$team_array[$index][4]."&lt;br&gt;";
          if ($team_array[$index][4] == $foo)
          {
              $tie_tm[] = $team_array[$index][0];
              $n++;
          }   
  
      }
  
      $k++;
  }
  echo "k - $k&lt;br&gt;";
  echo "l - $l&lt;br&gt;";
  echo "m - $m&lt;br&gt;";
  echo "n - $n&lt;br&gt;";
  
  echo "&lt;pre&gt;";
  print_r($tie_tm);
  </code></pre>
  
  <p>I have left the debugging bits in as they show the strange (to me) behavior. Specifically, if I comment out the line <code>"l++;"</code> I get LOTS more loops than I would expect. Running this code without the <code>"l++;"</code> line give me this:</p>
  
  <pre><code>k - 7
  l - 0
  m - 35
  n - 20
  Array
  (
  [0] =&gt; 68
  [1] =&gt; 68
  [2] =&gt; 68
  [3] =&gt; 68
  [4] =&gt; 68
  [5] =&gt; 72
  [6] =&gt; 72
  [7] =&gt; 72
  [8] =&gt; 72
  [9] =&gt; 72
  [10] =&gt; 65
  [11] =&gt; 65
  [12] =&gt; 65
  [13] =&gt; 65
  [14] =&gt; 65
  [15] =&gt; 62
  [16] =&gt; 62
  [17] =&gt; 62
  [18] =&gt; 62
  [19] =&gt; 62
  )
  </code></pre>
  
  <p>With it left in, I get:</p>
  
  <pre><code>k - 7
  l - 35
  m - 7
  n - 4
  Array
  (
  [0] =&gt; 68
  [1] =&gt; 72
  [2] =&gt; 65
  [3] =&gt; 62
  )
  </code></pre>
  
  <p>This is the result I want and expected. </p>
  
  <p>In the end, what I need is exactly what I am getting in the final result with 4 elements in the array. I would like to remove the debugging bits but need to understand how I might need to alter this code to keep my end result.</p>
  
  <p>Thanks in advance!</p>