foreach checkbox POST in php(php中的foreach复选框POST)
问题描述
基本上我的问题如下,如何在 PHP 中执行 $_POST 请求时选择已选中"复选框,目前我有复选框正在执行如下所示的数组.
Basically my question is the following, how can i select on "Checked" checkbox's while doing a $_POST request in PHP, currently i have the checkbox's doing an array as shown below.
<input type="checkbox" value="1" name="checkbox[]">
<input type="checkbox" value="2" name="checkbox[]">
<input type="checkbox" value="2" name="checkbox[]">
<input type="checkbox" value="3" name="checkbox[]">
我希望能够做这样的事情
I want to be able to do something like this
foreach(CHECKED CHECKBOX as CHECKBOX) {
echo CHECKBOX VALUE;
}
我试过做类似的事情,但它没有回响任何东西.
I've tried doing similar to that and it's not echoing anything.
推荐答案
foreach($_POST['checkbox'] as $value) {
}
请注意,$_POST['checkbox'] 将仅在至少一个复选框被选中时存在.因此,您必须在该循环之前添加一个 isset($_POST['checkbox']) 检查.最简单的方法是这样的:
Note that $_POST['checkbox'] will only exist if at least one checkbox is checked. So you must add an isset($_POST['checkbox']) check before that loop. The easiest way would be like this:
$checkboxes = isset($_POST['checkbox']) ? $_POST['checkbox'] : array();
foreach($checkboxes as $value) {
// here you can use $value
}
这篇关于php中的foreach复选框POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:php中的foreach复选框POST
基础教程推荐
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
