PHP array returning the same value
<p>I'm stuck on this and I'm not actually seeing where exactly the problem is.</p>

<p>I have a bunch of input tags which are placed like that:</p>

<pre><code>&lt;div class="col-md-3"&gt;
    &lt;label&gt;Material 1&lt;/label&gt;
    &lt;input hidden="hidden" name="idMaterial[]" value="13" type="text" /&gt;
    &lt;input class="form-control" name="total[]" type="text" /&gt;
&lt;/div&gt;

&lt;div class="col-md-3"&gt;
    &lt;label&gt;Material 2&lt;/label&gt;
    &lt;input hidden="hidden" name="idMaterial[]" value="8" type="text" /&gt;
    &lt;input class="form-control" name="total[]" type="text" /&gt;
&lt;/div&gt;
</code></pre>

<p>I have 20 input like that, the idea here is that if I write 10 in the Material 1's input field, my DB would receice something like:</p>

<pre><code>id         =&gt; A.I
idMaterial =&gt; 13
total      =&gt; 10
</code></pre>

<p>But once I run the code, it comes like that (repeating the idMaterial, even if I write in more than 1 input. It always repeat the first):</p>

<pre><code>idMaterial: 13
total: 10

idMaterial: 13
total: 20
</code></pre>

<p>That's the code I'm using to receive that form:</p>

<pre><code>$idMaterial = array();
$total  = array();

if($this-&gt;input-&gt;post('total')){
    foreach($this-&gt;input-&gt;post('idMaterial') as $row){
        $idMaterial = $row;

        foreach($this-&gt;input-&gt;post('total') as $row2){
            $total  = $row2;

            echo 'Material: '. $idMaterial .'&lt;br&gt; Total: '. $total. '&lt;br&gt;&lt;br&gt;'; // TESTING THE OUTPUT
            $query = $this-&gt;pedido-&gt;salvaLabMaterial($total, $idMaterial); // I'M SENDING THE DATA TO MODEL HERE
        }
    }
}
</code></pre>

<p>Any tips is very welcome.</p>