May172012
php自动输出select函数
作者:黑♂白 发布:2012-05-17 13:40:55 分类: web后端
php中自动生成select的option项,这样一个函数在php开过过程中是经常用到得。有必要将其整理为一个公用函数,公用函数整理如下:
function get_select_html($msg_list,$msg_val=""){
$arr_list=$msg_list;
if(!is_array($arr_list)) return "";
$str_return="";
if(is_assoc($arr_list)){
foreach($arr_list as $key=>$item){
$str_sel="";
if($key==$msg_val) $str_sel=" selected";
$str_return.="";
}
}else{
foreach($arr_list as $item){
$str_sel="";
if($item==$msg_val) $str_sel=" selected";
$str_return.="";
}
}
return $str_return;
}
上面函数返回的是一个select的option项目,$msg_list是一个array($key=>$value),$msg_val是需要默认选中的值。
您还未登录,需要登录后才能发言