簡體   English   中英

PHP推送到數組問題

[英]PHP Pushing to array issue

我正在嘗試構建一個數組,然后遍歷它,但不斷出現未定義的索引錯誤。 我在這里做錯了什么? 陣列構建不正確嗎? 如果我不將新項目放入其中,則代碼可以正常工作。 一旦向其中添加更多元素,整個過程就會破裂。

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)

似乎數組有一個多余的層次被忽略了……也許嘗試這樣的事情:

for ($i = 0; $i < count($pickUpData); $i++) {
  foreach ($pickUpData[$i] 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'];
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM