gpt4 book ai didi

mysql - 插入多列表 laravel

转载 作者:行者123 更新时间:2023-11-29 05:52:36 25 4
gpt4 key购买 nike

我想知道如何在 laravel 模型中使用像这样的 2 个数组将一组数据插入到一个表中

   $attributes  =array('title','description'); 
$options =array('test','blahblahblah');

table 是这样的

题目测试

描述等等

到目前为止,我已经做到了这一点

 $values = array(
array($attributes => $options),
);

但是它说

非法数组键类型数组less数组和对象不能用作数组键。

我尝试的任何方式都有不同的错误但大部分错误是非法偏移类型你有什么建议吗?

最佳答案

您可以将两个数组与 array_combine 结合使用.它需要一个数组作为键,一个数组作为值。

$attributes = array('title', 'description');
$options = array('test', 'blahblahblah');

$values = array_combine($attributes, $options);

结果:

array:2 [▼
"title" => "test"
"description" => "blahblahblah"
]

关于mysql - 插入多列表 laravel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52759309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com