php - 如何在 foreach 循环的每个迭代中更改 post 值
问题描述
我需要在 foreach 循环的每次迭代中更改 post 值。这是我的代码:
foreach ($amovess as $key => $val) {
$actions = $amovess[$key];
$lastid = $database->insert("tablename", [
"Action" => $actions,
"barcode"=>$data['barcode1txt'],
"barcode"=>$data['barcode2txt']
]);
}
我希望 foreach 循环的第一次移动$data['barcode1txt']
应该插入,第二次移动$data['barcode2txt']
应该插入。请指导我。
解决方案
我不知道你的关键价值是什么。你可以这样做
<?php
$i =1;
foreach ($amovess as $key => $val) {
$actions = $amovess[$key];
$lastid = $database->insert("tablename", [
"Action" => $actions,
"barcode" => $data['barcode' . $i . 'txt']
]);
$i++;
}
?>
推荐阅读
- c - (-1 >= sizeof(buffer)) 怎么可能是真的?程序无法获得正确的比较结果
- ssl - 如何使用 Nginx 为不同的位置启用不同的 SSL 证书?
- python - 有没有办法默认从 sdist 安装 Python 包?
- video - 使用 C 库将帧编码为视频
- javascript - jQuery html 脚本 document.currentScript
- authorization - Swagger-ui:如何配置以服务于 MVC 核心项目
- hive - 在 Hive 中,哪个查询更好,为什么?
- dart - Flutter:下拉列表中的选定值
- unicode - Unicode/迷你字母高于其他字符?
- java - 将 10 以下的所有素数乘以 1,2,3,4,5 的程序