返回

php——我一直遇到这个错误:非法字符串偏移量'product_id'[重复]

发布时间:2022-04-22 22:35:53 183
# 后端

我正在插入三维数组,因此尝试为每个循环使用嵌套数组。但我不断遇到错误:非法字符串偏移量“product_id”

我的代码是:

foreach($request->transfer as $key => $value){
            
    foreach($request->transfer[$key]['product'] as $n_key => $n_value){

        $storage_product = StorageProduct::create([
            'storage_id'   => $request->transfer[$key]['storage_id'],
            'product_id'   => $request->transfer[$key]['product'][$n_key]['product_id'],
            'transfer_id'  => $supply_to_storage->id,
            'quantity'     => $request->transfer[$key]['product'][$n_key]['quantity']
        ]);
    }
}

数组看起来是这样的:我正在添加一些虚拟文本,因为它正在通知我;主要是“代码”;。Lorem Ipsum只是印刷和排版行业的虚拟文本。自16世纪以来,Lorem Ipsum一直是行业标准的虚拟文本

 Array
 (
  [0] => Array
      (
          [product] => Array
              (
                [0] => Array
                    (
                        [product_id] => 1
                        [quantity] => 12
                        [total_quantity] => 12
                        [rate] => 14
                    )

                [product_varient_id] => 2
                [1] => Array
                    (
                        [product_id] => 2
                        [quantity] => 4
                        [total_quantity] => 12
                        [rate] => 11
                    )

            )

        [transfer_number] => 
        [storage_id] => 2
        [storage_product_quantity] => 12
        [status] => 8
    )

[1] => Array
    (
        [product] => Array
            (
                [0] => Array
                    (
                        [product_id] => 1
                        [quantity] => 11
                        [total_quantity] => 12
                        [rate] => 5
                    )

                [product_varient_id] => 1
            )

        [transfer_number] => 
        [storage_id] => 1
        [storage_product_quantity] => 12
        [status] => 8
    )

 )
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像