我有一个需要发布的表单复选框组。
<input type="checkbox" value="true" checked name="chk0[]">
<input type="checkbox" value="false" name="chk0[]">
<input type="checkbox" value="false" name="chk0[]">
<input type="checkbox" value="true" checked name="chk0[]">
<input type="checkbox" value="true" checked name="chk1[]">
<input type="checkbox" value="false" name="chk1[]">
<input type="checkbox" value="true" checked name="chk1[]">
<input type="checkbox" value="false" name="chk1[]">
请注意,在第一组中,检查了1和4。在第二组中,检查1和3。
当我发布此内容时,我依次获得以下已选中复选框的发布值:
[chk0] => Array (
[0] => true
[1] => true
)
[chk1] => Array (
[0] => true
[1] => true
)
我如何确保我得到这样的发布值:
[chk0] => Array (
[0] => true
[3] => true
)
[chk1] => Array (
[0] => true
[2] => true
)
我想知道选中的复选框的键,而不是按顺序显示。
谢谢
参考方案
<input type="checkbox" value="true" checked name="chk0[0]">
<input type="checkbox" value="false" name="chk0[1]">
<input type="checkbox" value="false" name="chk0[2]">
<input type="checkbox" value="true" checked name="chk0[3]">
<input type="checkbox" value="true" checked name="chk1[0]">
<input type="checkbox" value="false" name="chk1[1]">
<input type="checkbox" value="true" checked name="chk1[2]">
<input type="checkbox" value="false" name="chk1[3]">
明白了吗?<input name="chk0[1]" ...>
框的工作方式类似于PHP中的数组元素。您可以指定索引,将其作为$_POST['chk0'][1]
元素原样传输到PHP。
有没有一种方法可以使div上的click事件与表单环境中的单选按钮相同?我只希望下面的div提交值,单选按钮很丑代码输出如下:<input id="radio-2011-06-08" value="2011-06-08" type="radio" name="radio_date…
PHP Count数组元素 - php嗨,有人可以解释为什么这会返回“数组由0个元素组成”。 :$arr = array(1,3,5); $count = count($arr); if ($count = 0) { echo "An array is empty."; } else { echo "An array has $count elements.…
PHP:从函数返回值并直接回显它? - php这可能是一个愚蠢的问题,但是……的PHPfunction get_info() { $something = "test"; return $something; } html<div class="test"><?php echo get_info(); ?></div> 有没有办…
php-printf和sprintf具有不同的输出 - php我编写了以下微型php程序来测试printf和sprintf:<?php $str_1 = printf("%x%x%x", 65, 127, 245); $str_2 = sprintf("%x%x%x", 65, 127, 245); echo $str_1 . "\n"; echo $s…
使用Ajax呈现html表 - php我想知道如何实现以下项目其实我有一个php代码,可以渲染一张桌子<table id = "oldata" class ="table table-bordered"> <thead> <tr class ="success"> <th class="…