如何顯示先前選中的複選框選中狀態。 在我的表中的值存儲像電冰箱,空調器,電視機在一列如何使用php顯示以前選中的複選框
<?php
$answered="Refrigerator, Airconditioner, Television";
$answer_options=array("Refrigerator","Airconditioner","tv");
$ans_checked=explode(',',$answered);
echo "<pre>";
//print_r($ans_checked);
$checked='';
foreach($answer_options as $a)
{
echo $a."<br>";
//print_r($ans_checked);
if(in_array($a,$ans_checked))
{
$checked="checked";
}
//echo "$a<br>";
echo "<input type='checkbox' ".$checked." >$a<br>";
}
?>
什麼是錯的代碼? – NID