如何动态地将数组值添加到字符串中?

时间:2019-04-11 07:10:09

标签: php arrays

我有一个带有数据库列名称的数组。

docker commit

我需要将POST值动态添加到来自数组$db_cols = ['name', 'age', 'gender']; 的数据库查询中。结果必须是这样的。

$db_cols

但是我需要修改$db->query('INSERT INTO tbl (id, '.implode(', ', $db_cols).', order) VALUES (?, '.str_repeat('?, ', count($db_cols)).' ?)', [$_POST['id'],$_POST['name'], $_POST['age'], $_POST['gender'], $order]); 上的这段代码

查询结果:

$_POST['name'], $_POST['age'], $_POST['gender']

谢谢您的帮助。

0 个答案:

没有答案
相关问题