我正在尝试获取表单数组中的复选框数组。我试图首先将数据作为表单数组获取,然后在数组中获取复选框数组。
<form name="preview" id="post" action="" method="post">
<input type="hidden" name="category[$id]" />
<input type="checkbox" name="subcat[]" value="something" />
<input type="checkbox" name="subcat[]" value="somewhere" />
<input type="checkbox" name="subcat[]" value="something" />
<input type="checkbox" name="subcat[]" value="somewhere" />
<input type="hidden" name="category[$id]" />
<input type="checkbox" name="subcat[]" value="something" />
<input type="checkbox" name="subcat[]" value="somewhere" />
<input type="checkbox" name="subcat[]" value="something" />
<input type="checkbox" name="subcat[]" value="somewhere" />
<input class="button-primary" name="submit_preview" value="Submit Selected Tees" type="submit">
</form>
if (isset($_POST['submit_preview'])) {
foreach ( $_POST[ 'category' ] as $id ) {
foreach ( $_POST[ 'subcat' ][$id] as $subcat ) {
echo $subcat;
}
}
}