selected 下拉選單的快速編寫 function

PHP selected 下拉選單的快速編寫 function

function selectedCH($value,$seleted,$str) {
if($value==$seleted){
$OutSelectEd = '<option value="'.$value.'" selected>'.$str;
} else {
$OutSelectEd = '<option value="'.$value.'">'.$str;
}
return $OutSelectEd;
}

$OutBody = '你一餐吃幾碗飯: <select>';
$OutBody .= selectedCH(1,2,'一碗飯');
$OutBody .= selectedCH(2,2,'二碗飯');
$OutBody .= selectedCH(3,2,'三碗飯');
$OutBody .= '</select>';

echo $OutBody;

輸出:
你一餐吃幾碗飯: <select><option value="1">一碗飯<option value="2" selected>二碗飯<option value="3">三碗飯</select>


你一餐吃幾碗飯: