PHP foreach loops
<p>This is making me insane.  I've validated my input/outputs, and I'm still getting unexpected behavior.  It should be 2, but it's doing numa numa.  What am I missing?</p>

<p><strong>Input:</strong></p>

<pre><code>data
Array
(
    [0] =&gt; Array
        (
            [lineId] =&gt; 1
            [quantity] =&gt; 2
            [costPerItem] =&gt; 16.585
            [itemId] =&gt; 1
        )

)
</code></pre>

<p><strong>Code:</strong></p>

<pre><code>printr( $data, 'data' );
foreach( $data as $i =&gt; $value ){
    foreach( $value as $key =&gt; $a ){
        echo 'key: '.$key.' - a: '.$a.'&lt;br /&gt;';
        ( $key == 'quantity' ) ? $dataQuantity[$i] = $a : $dataQuantity[$i] = 'numanuma'; 
    }
}
printr( $dataQuantity, 'data quantity' );
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>key: lineId - a: 1
key: quantity - a: 2
key: costPerItem - a: 16.585
key: itemId - a: 1

data quantity
Array
(
    [0] =&gt; numanuma
)
</code></pre>
