checkbox checked 複選選單的快速編寫 function

PHP checkbox checked 複選選單的快速編寫 function

<?php
function CheckBoxCH($value,$checked,$name) {
if($value==$checked){
$OutCheckBoxEd = '<input name="'.$name.'" type="checkbox" value="'.$value.'" checked>';
} else {
$OutCheckBoxEd = '<input name="'.$name.'" type="checkbox" value="'.$value.'">';
}
return $OutCheckBoxEd;
}

$OutBody = '你一餐吃幾碗飯: ';
$OutBody .= CheckBoxCH(1,2,'eat').'一碗飯';
$OutBody .= CheckBoxCH(2,2,'eat').'二碗飯';
$OutBody .= CheckBoxCH(3,2,'eat').'三碗飯';

echo $OutBody;
?>

輸出:
你一餐吃幾碗飯: <input name="eat" type="checkbox" value="1">一碗飯<input name="eat" type="checkbox" value="2" checked>二碗飯<input name="eat" type="checkbox" value="3">三碗飯

你一餐吃幾碗飯: 一碗飯二碗飯三碗飯