我的項目有一個由請求組成的數組,其中包含輸入數組,如下所示: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); }
在 foreach 中運行時,數組的數組返回無意義
慕婉清6462132
2023-07-01 15:08:59