简体   繁体   English

PHP推送到数组问题

[英]PHP Pushing to array issue

I'm trying to build an array then traverse it but keep getting undefined index errors. 我正在尝试构建一个数组,然后遍历它,但不断出现未定义的索引错误。 What am I doing wrong here? 我在这里做错了什么? Is the array not built correctly? 阵列构建不正确吗? If I don't push new items into it, the code works fine. 如果我不将新项目放入其中,则代码可以正常工作。 As soon as I add more elements into it, the whole thing breaks. 一旦向其中添加更多元素,整个过程就会破裂。

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)

It looks like the array has an extra level that's being overlooked... Maybe try something like this: 似乎数组有一个多余的层次被忽略了……也许尝试这样的事情:

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