title: PHP foreach loop through multidimensional array
body: <p>I have an multidimensional array, how can I use it? I want to use each separate array in a <code>for</code> loop.</p>
  
  <p>What I want to achive is to be able to put each part in my database like
  entry in db no. 0 -> 1 and 4
  entry in db no. 1 -> 5 and 6
  entry in db no. 2 -> 1 and 4 and 5 and 6</p>
  
  <p>I have this code:</p>
  
  <pre><code>&lt;?php 
      print_r($calculatie_id); 
      for ($i=0; $i&lt;=3; $i++) 
  { 
  ?&gt;  
  &lt;tr&gt; 
      &lt;td&gt; 
  
      &lt;?php 
      foreach ($calculatie_id[$i] as $value) 
      { 
          echo $value; 
      } 
  ?&gt;
  
  print_r($calculatie_id); gives 
  Array ( [0] =&gt; Array ( [0] =&gt; 4 [1] =&gt; 6 ) [1] =&gt; Array ( [0] =&gt; 1 [1] =&gt; 5 ) [2] =&gt; Array ( [0] =&gt; 5 [1] =&gt; 6 ) [3] =&gt; )
  </code></pre>
  
  <p>But when using the <code>foreach</code> I only get 46</p>
  
  <p>Some extra information:</p>
  
  <p>This array is created by an multiple select in an for loop. Any other suggestions are welcome.</p>
  
  <pre><code>    for ($i=0; $i&lt;=$aantal_regels_corr; $i++)
  { 
  ?&gt; 
  &lt;tr&gt;
      &lt;td&gt;
  
          &lt;?php 
          // maak select name
          $calculatie_id = 'calculatie_id'.$i;
  
          // rest van formulier
          if($error_vergeten[$i] == "ja"){ $error_omschr = $error_omschr_vergeten[$i]; include('includes/input_error.php'); } ?&gt;&amp;nbsp;&lt;textarea rows="7" cols="80" name="omschrijving[]" /&gt;&lt;?php echo $omschrijving[$i]; ?&gt;&lt;/textarea&gt;
      &lt;/td&gt;
      &lt;td colspan="2"&gt;
          &lt;select multiple="multiple" width="50" size="7" name="&lt;?php echo $calculatie_id ?&gt;[]" style="width: 150px"&gt;
          &lt;?php
              $sql_calc = "select id, naam, actief from sp_calculatie WHERE (offerte_id = '".$row['off_offerte']."' OR offerte_id = '".$offerte_id."') AND actief = 'ja' ORDER BY id ASC";
              $res_calc = mysql_query($sql_calc,$con);  
              while ($row_calc = mysql_fetch_assoc($res_calc)){
          ?&gt;
              &lt;option value="&lt;?php echo $row_calc["id"] ?&gt;"&gt;&lt;?php if (empty($row_calc["naam"])) { echo $row_calc["id"]; } else { echo $row_calc["naam"]; } ?&gt;&lt;/option&gt;
          &lt;?php } ?&gt;&lt;/select&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php } ?&gt;
  </code></pre>