我知道在其他帖子中已经深入讨论了这个问题,但我无法将我的var_dump帖子打印出来,而不是检查的最后一个复选框。它永远不会输出多个选中的复选框,即使肯定有多个被检查
我的HTML:
<form method="post" class="form" role="form" action="/users/teacher_account" name="teacher_account_form" id="teacher_account_form" >
<label class='checkbox-inline'><input type='checkbox' name='subject_id[]' value=1 checked >Math</label>
<label class='checkbox-inline'><input type='checkbox' name='subject_id[]' value=2 checked >Algebra</label>
<label class='checkbox-inline'><input type='checkbox' name='subject_id[]' value=3 checked >SAT</label>
<label class='checkbox-inline'><input type='checkbox' name='subject_id[]' value=4 >
我的php:
var_dump($_POST);
foreach ($_POST['subject_id'] as $subject)
{
echo $subject . "<br>";
}
我的var转储结果:
array(2) { ["subject_id"]=> string(1) "6" ["update_button"]=> string(0) "" }
我错误的foreach尝试结果:
Warning: Invalid argument supplied for foreach()