我正在尝试使用php程序从另一个数组中的数据构建多维数组。
$n = 13;
while($n <=22){
$itemName = $outputFields['FLD_'+ $n +'_002']['value'];
$itemUM = $inputFields['FLD_'+ $n +'_029']['value'];
$itemUnits = $inputFields['FLD_'+ $n +'_032']['value'];
$itemUnitsPrice = $outputFields['FLD_'+ $n +'_045']['value'];
$itemExtendedPrice = $outputFields['FLD_'+ $n +'_060']['value'];
$itemLT = $outputFields['FLD_'+ $n +'_076']['value'];
$arrItems[$itemName][$itemUM][$itemUnits][$itemUnitsPrice][$itemExtendedPrice][$itemLT] = true;
$n++;
}
最终结果应该是这样的:
Array
(
[13] => Array
(
[itemName]
[itemUM]
[itemUnits]
...
)
...
[22] => Array
(
[itemName]
[itemUM]
[itemUnits]
...
)
)
目前收到“未定义的偏移”错误。
答案 0 :(得分:0)
试试这段代码:
$n = 13;
while($n <=22){
$arrItems[$n]['itemName'] = $outputFields['FLD_'. $n .'_002']['value'];
$arrItems[$n]['itemUM'] = $inputFields['FLD_'. $n .'_029']['value'];
$arrItems[$n]['itemUnits'] = $inputFields['FLD_'. $n .'_032']['value'];
$arrItems[$n]['itemUnitsPrice'] = $outputFields['FLD_'. $n .'_045']['value'];
$arrItems[$n]['itemExtendedPrice'] = $outputFields['FLD_'. $n .'_060']['value'];
$arrItems[$n]['itemLT'] = $outputFields['FLD_'. $n .'_076']['value'];
$n++;
}