这让我发疯了。我已经验证了我的输入/输出,但仍然出现意外行为。它应该是 2,但它正在做 numa numa。我错过了什么?
输入:
data
Array
(
[0] => Array
(
[lineId] => 1
[quantity] => 2
[costPerItem] => 16.585
[itemId] => 1
)
)
代码:
printr( $data, 'data' );
foreach( $data as $i => $value ){
foreach( $value as $key => $a ){
echo 'key: '.$key.' - a: '.$a.'<br />';
( $key == 'quantity' ) ? $dataQuantity[$i] = $a : $dataQuantity[$i] = 'numanuma';
}
}
printr( $dataQuantity, 'data quantity' );
输出:
key: lineId - a: 1
key: quantity - a: 2
key: costPerItem - a: 16.585
key: itemId - a: 1
data quantity
Array
(
[0] => numanuma
)