dtmjl4427 2016-10-11 21:56
浏览 220
已采纳

Laravel 5 - 如何为raravel数组添加多个参数以进行数据库插入?

I have an array of 3 companies, which need to be inserted into the db but with 2 additional parameters added to them.

$companyList = [{"name": "apple", "founder": "steve"},
                {"name": "google", "founder": "larry"},
                {"name": "facebook", "founder": "mark"},
               ];

Need to append these 2 parameters for each company (issue is in this step):

$companyListFinal = [];
foreach ($companyList as $company) {
  $companyListFinal[] = array_add($company,['keyAppend1' => 'key 1 appended',
                                            'keyAppend2' => 'key 2 appended'];
}

The final step is to insert the company list with the appended values into the DB:

DB::table('companies')->insert($companyListFinal);

I can't seem to be able to append the 2 new parameters to create the final array to insert:$companyListFinal

What's the correct way to add the parameters to each company so they are all inserted at bulk?

  • 写回答

2条回答 默认 最新

  • douhao2153 2016-10-11 22:59
    关注

    You need to use array_merge instead of array_add

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥20 MATLAB绘制两隐函数曲面的交线
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃