我有一个包含这样的表单字段的表单:
<form action="versions000003.php" method="post">
<input type='hidden' name='method' value='recalculate' />
<table>
<tr>
<td>1</td>
<td><input type='checkbox' id='thread_1|1' name='add[]' value='1|1' /></td>
<!-- ... increment to 43 -->
<td><input type='checkbox' id='thread_1|43' name='add[]' value='1|43' /></td>
</tr>
<tr>
<td>2</td>
<td><input type='checkbox' id='thread_2|1' name='add[]' value='2|1' /></td>
<!-- ... increment to 43 -->
<td><input type='checkbox' id='thread_2|43' name='add[]' value='2|43' /></td>
</tr>
<td>3</td>
<td><input type='checkbox' id='thread_3|1' name='add[]' value='3|1' /></td>
<!-- ... increment to 43 -->
<td><input type='checkbox' id='thread_3|43' name='add[]' value='3|43' /></td>
</tr>
</table>
<button type='submit' class='btn btn-danger'>Go</button>
</form>
提交表单后,我这样做:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$mode = $_POST['method'];
if ($mode = "ReCalculate") {
if (is_array($_POST['add'])) {
print_r($_POST['add']);
foreach ($_POST as $key => $value)
print_r($value);
}
}
}
根据所选内容,生成的数组可能如下所示,例如:
Array
(
[0] => 1|1
[1] => 1|2
[2] => 1|3
[3] => 1|4
[4] => 1|5
[5] => 1|6
[6] => 1|32
[7] => 1|35
[8] => 2|1
[9] => 2|5
[10] => 3|1
[11] => 3|8
[12] => 3|11
[13] => 3|13
[14] => 3|35
)
我想知道如何更改表单处理逻辑,在本例中以数组中的3个元素结束。我希望将管道之后的值按管道前的值分组 - 最后得到:
Array
(
[0] => 1|1,2,3,4,5,6,32,35
[1] => 2|1,5
[2] => 3|1,8,11,13,25
)
这是可能的 - 如果是这样的话,我会对如何达到这个结果的任何建议表示感谢。感谢