使用PHP生成单选按钮组
这是一个以HTML形式创建一组单选按钮的功能。这三个参数是:
$name:单选组的名称。
$options:要包含在单选按钮组中的项目的关联数组。
$default:单选按钮的默认值。
function createRadio($name,$options,$default=''){
$name = htmlentities($name);
$html = '';
foreach($options as $value=>$label){
$value = htmlentities($value);
$html .= ''.$label.'
'."\n";
};
return $html;
}您可以通过以下方式调用该函数:
$array = array('one'=>'One',
'two'=>'Two',
'three'=>'Three',
'four'=>'Four');
echo createRadio('numbers',$array,'three');产生以下输出:
One
Two
Three
Four