I want get (handling) values input and checkboxes as following example, without change in name element in checkboxes, I tried as following but this don’t work:
DEMO: http://codepad.viper-7.com/4ldRKV
<?php
if($_POST){
//foreach ($_POST['cDA'] as $idx => $value) {
foreach ($_POST as $idx => $value) {
echo '<pre>';
print_r($_POST);
}
//}
}
?>
<form action="#" method="post">
<input type="text" name="cDI[]" value="F1">
<input type="checkbox" name="cDA[0][]" value="11" checked>
<input type="checkbox" name="cDA[0][]" value="11" checked>
<input type="checkbox" name="cDC[1][]" value="22" checked>
<input type="checkbox" name="cDC[1][]" value="22" checked>
</br>
<input type="text" name="cDI[]" value="F2">
<input type="checkbox" name="cDA[0][]" value="33" checked>
<input type="checkbox" name="cDA[0][]" value="33" checked>
<input type="checkbox" name="cDC[][]" value="44" checked>
<input type="checkbox" name="cDC[][]" value="44" checked>
</br>
<input type="text" name="cDI[]" value="F3">
<input type="checkbox" name="cDA[0][]" value="55" checked>
<input type="checkbox" name="cDA[0][]" value="55" checked>
<input type="checkbox" name="cDC[][]" value="66" checked>
<input type="checkbox" name="cDC[][]" value="66" checked>
</br>
<input type="submit" value="Submit">
</form>
I want in output as: ( how should change html and php to getting following result? )
Array
(
[cDI] => Array
(
[0] => F1
[1] => F2
[2] => F3
)
[cDA] => Array
(
[0] => Array
(
[0] => 11
[1] => 11
)
[1] => Array
(
[0] => 33
[1] => 33
)
[2] => Array
(
[0] => 55
[1] => 55
)
)
[cDC] => Array
(
[0] => Array
(
[0] => 22
[1] => 22
)
[1] => Array
(
[0] => 44
[1] => 44
)
[2] => Array
(
[0] => 66
[1] => 66
)
)
)
If you use
cDA[0][]as the name of a collection of input boxes, it will turn$_POST['cDA']into this:Using
cDC[][]as the names of your input boxes, you will end up with this array in$_POST['cDC']:To make them group properly you have to set the value between the first square brackets explicitly:
Demo