您有个知识币

【退出】

php自动输出select函数

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是需要默认选中的值。

本文固定链接: http://www.webzhishi.com/php_select_1/ | web知识网

php自动输出select函数:等您坐沙发呢!

发表评论