'undefined offset errors' php 多维数组
'undefined offset errors' php multidimensional array
我正在尝试获取一个 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]
...
)
)
目前出现 "undefined offset" 个错误。
试试这个代码:
$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++;
}
我正在尝试获取一个 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]
...
)
)
目前出现 "undefined offset" 个错误。
试试这个代码:
$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++;
}