1
我想創建一個數組,其中包含多個存儲複選框結果的數組。表格數組複選框
category->subcategory->choice
我不知道這甚至有可能,但我想是這樣的,也許:
<input type="hidden" name="category[]" />
<input type="checkbox" name="subcat1[]" value="something" />
<input type="checkbox" name="subcat1[]" value="somewhere" />
<input type="checkbox" name="subcat2[]" value="something" />
<input type="checkbox" name="subcat2[]" value="somewhere" />
我希望能夠採取類別陣列循環通過它用PHP這樣的:
foreach($_POST['category'] as $sub){
switch($sub){
case 'subcat1':
foreach($sub as $val){
//prepare $val to insert into database X
}
break;
case 'subcat2':
foreach($sub as $val){
//prepare $val to insert into database Y
}
break;
}
}
是的,這是可能的,但具體是什麼問題? –