radio checked 選單的快速編寫 function

PHP radio checked 選單的快速編寫 function

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

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

echo $OutBody;
?>
輸出:
你一餐吃幾碗飯: <input name="eat" type="radio" value="1">一碗飯<input name="eat" type="radio" value="2" checked>二碗飯<input name="eat" type="radio" value="3">三碗飯
你一餐吃幾碗飯: 一碗飯二碗飯三碗飯