我需要在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']
时应该插入。请引导我。
答案 0 :(得分:2)
我不知道您的关键价值是什么。你可以这样做
<?php
$i =1;
foreach ($amovess as $key => $val) {
$actions = $amovess[$key];
$lastid = $database->insert("tablename", [
"Action" => $actions,
"barcode" => $data['barcode' . $i . 'txt']
]);
$i++;
}
?>