我想構建一個數組然後遍歷它,但不斷收到未定義的索引錯誤。我在這裏做錯了什麼?該數組未正確構建?如果我不推送新項目,代碼工作正常。一旦我添加更多元素,整個事情就會崩潰。PHP推動陣列問題
foreach($CustPOIDs as $key => $val){
$CustPOID = $val['CustPOID'];
//Call this method for each CustPOID
$tender = new BOL($CustPOID);
$pickUpData[]=$tender->getPickupInfo();
}
}
foreach ($pickUpData as $key => $val) {
$LoadDate = $val['POLineLoadDate'];
$POLineComments = $val['POLineComment'];
$ProdID = $val['ProdID'];
$ShipperId = $val['ShipperId'];
$ShipDesc = $val['Description'];
$shAddress = $val['Address1'];
$shState = $val['State'];
$shPhone = $val['Phone'];
$pdProdDesc = $val['ProdDesc'];
$pdCommodity = $val['Commodity'];
$pdWeight = $val['ProdWeight'];
}
array (size=2)
0 =>
array (size=1)
0 =>
array (size=12)
'POLineLoadDate' => string '1969-12-31 00:00:00' (length=19)
'POLineComment' => string '56sent NOT 60' (length=13)
'ProdID' => string '322' (length=3)
'ShipperId' => null
'Description' => null
'Address1' => null
'City' => null
'State' => null
'Phone' => null
'ProdDesc' => string 'SLESS 60CT Bin/Bin WMELON US#1' (length=30)
'Commodity' => string 'WATERMELON' (length=10)
'ProdWeight' => string '0' (length=1)
1 =>
array (size=2)
0 =>
array (size=12)
'POLineLoadDate' => string '1900-01-01 00:00:00' (length=19)
'POLineComment' => string '' (length=0)
'ProdID' => string '192' (length=3)
'ShipperId' => null
'Description' => null
'Address1' => null
'City' => null
'State' => null
'Phone' => null
'ProdDesc' => string 'RND WHT US#1 SIZE A PAPR POTAT' (length=30)
'Commodity' => string 'POTATO' (length=6)
'ProdWeight' => string '0' (length=1)
1 =>
array (size=12)
'POLineLoadDate' => string '1900-01-01 00:00:00' (length=19)
'POLineComment' => string '' (length=0)
'ProdID' => string '187' (length=3)
'ShipperId' => null
'Description' => null
'Address1' => null
'City' => null
'State' => null
'Phone' => null
'ProdDesc' => string 'IDAHO US#1 6-10OZ POLY POTATO' (length=29)
'Commodity' => string 'POTATO' (length=6)
'ProdWeight' => string '0' (length=1)
「*,但不斷收到未定義的索引錯誤* 「 - 請發佈確切的錯誤消息。 –
在第一個foreach中你已經有了一個額外的花括號 - 可能只是其餘的代碼剩餘的,但我認爲我會指出它 –
額外的花括號是針對它上面的條件。通知:未定義指數:POLineLoadDate在C:\瓦帕\ WWW \ XXXXXXX \ takeIII \ lEditor.php上線245 調用棧 #\t \t時間內存\t \t功能位置 \t 0.0010 211552 \t {主}()\t .. \ lEditor.php:0 – Waragi