Why in following PHP code output var_dump
for checkbox($service_un
) in offset[1] is empty?
this variable($service_un
) get values checkbox_un
in following HTML code that are as array but not know why in output var_dump
on offset[1] values input:name="checkbox_un[1][]"
are empty. how can fix it?
array(2) {
[0] = > array(2) {
[0] = > string(7)"Minibar" [1] = > string(12)"Teahouse"
}[1] = > array(2) {
[0] = > string(0)"" [1] = > string(0)""
}
}
Codes:
<input type="text" name="name_un[]" value="jack">
<input type="checkbox" name="checkbox_un[0][]" value="Minibar">
<input type="checkbox" name="checkbox_un[0][]" value="Teahouse">
<input type="text" name="name_un[]" value="jim">
<input type="checkbox" name="checkbox_un[1][]" value="Television">开发者_JAVA百科;
<input type="checkbox" name="checkbox_un[1][]" value="Foreign">
<?php
$name_un = $this->input->post('name_un');
$service_un = $this->input->post('checkbox_un');
var_dump($service_un); // This output
?>
Checkbox values are only set (to the value in the HTML input tag), if the checkbox has been selected (the checkmark was set).
As long as it doesn't, the offset will not be set. Try it for yourself.
精彩评论