PHP推送阵列问题

时间:2014-06-13 18:03:16

标签: php arrays

我试图构建一个数组然后遍历它但继续获得未定义的索引错误。我在这做错了什么?阵列是否未正确构建?如果我不将新项目推入其中,则代码可以正常工作。一旦我添加更多元素,整个事情就会破裂。

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)

1 个答案:

答案 0 :(得分: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'];
  }
}