小编Nat*_*at_的帖子

PHP中的foreach - 如何在变量中传递值?

所以问题是,我有一个HTML表单,复选框作为输入选项.我想将所有选定的选项保存为一个变量中的字符串(!).

我很确定解决方案是一个foreach循环,但我的工作不起作用.它只返回最后选择的值.

我怎样才能解决这个问题?

HTML

<form action="" method="post">
<label>category:<br/>
     one <input type="checkbox" name ="ber[]" value="one"><br/>
     two <input type="checkbox" name ="ber[]" value="two"><br/>
     thr <input type="checkbox" name ="ber[]" value="three"><br/>
     fou <input type="checkbox" name ="ber[]" value="four"><br/>
</form>
Run Code Online (Sandbox Code Playgroud)

PHP

foreach ($_POST['ber'] as $value) {
$ber = "$value. ', '"
}
Run Code Online (Sandbox Code Playgroud)

html php arrays checkbox foreach

0
推荐指数
1
解决办法
195
查看次数

标签 统计

arrays ×1

checkbox ×1

foreach ×1

html ×1

php ×1