【发布时间】:2017-01-11 09:11:15
【问题描述】:
我有从 mysql 检索的数组。
Array item_category 是一个显示所有类别的数组。
Array selected_category 是一个显示所选类别的数组。
$item_category[32]="western food";
$item_category[33]="chinese food";
$item_category[34]="mix food";
$item_category[35]="japanese food";
$item_category[36]="korean food";
$item_category[37]="italian food";
$selected_category[32]="western food";
$selected_category[33]="chinese food";
$selected_category[34]="mix food";
foreach ($item_category as $key => $value) {
echo '<input type="checkbox" name="check_list[] "value="'.$key.'"> '.$value.'<br>';
}
使用 foreach 循环显示所有类别
选中数组
$selected_category中的复选框。
所以我的问题是如何像屏幕截图一样选中复选框,因为它们在这 2 个数组中具有相同的“Key”?我尝试了以下方法,但它没有按我的预期工作。
$checked = true ? "checked" : "";
echo '<input type="checkbox" ' . $checked . ' name="check_list[] "value="'.$key.'"> '.$value.'<br>';
【问题讨论】: