亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 foreach 中運行時,數組的數組返回無意義

在 foreach 中運行時,數組的數組返回無意義

PHP
慕婉清6462132 2023-07-01 15:08:59
我的項目有一個由請求組成的數組,其中包含輸入數組,如下所示:array:8 [▼  "type_id" => array:1 [▼    0 => "1"  ]  "zip_code" => array:1 [▼    0 => "88801500"  ]  "street_address" => array:1 [▼    0 => "Avenida Getúlio Vargas"  ]  "number" => array:1 [▼    0 => "asdasd"  ]  "street_address_2" => array:1 [▼    0 => "asdasd"  ]  "city_id" => array:1 [▼    0 => "4384"  ]  "neighborhood" => array:1 [▼    0 => "Centro"  ]  "created_by" => 2]但是當我嘗試在 foreach 上運行所述數組以將其插入數據庫時,我得到的結果沒有意義:array:1 [▼  0 => "1"]我的代碼:dd($dataEnderecos); //This is for debug purposes, it shows the initial array on this question.        foreach ($dataEnderecos as $enderecos) {            dd($enderecos); //This is for debug purposes, it shows the secondary array on this question.            $enderecoID = $this->address->create($enderecos)->id;            $this->repository->enderecos()->attach($enderecoID);        }
查看完整描述

1 回答

?
蝴蝶不菲

TA貢獻1810條經驗 獲得超4個贊

我設法通過使用 for 循環并使用另一個變量來接收初始數組的結果來解決此問題:


for ($i = 0; $i < $limit; $i++) {

   $insert = array(

      'type_id'          =>   $dataEnderecos['type_id'][$i],

      //                         ^^^^           ^^^^   ^^^^

      //                Initial Array  Secondary Array Index

   );

}


查看完整回答
反對 回復 2023-07-01
  • 1 回答
  • 0 關注
  • 103 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號