This article introduces a function that uses PHP to automatically output (construct) a select form. Friends in need can refer to it. The following functions are implemented: Automatically generate select options. The code is as follows: $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; } ?>
Copy after login
Code description: Returns a select option item, $msg_list is an array ($key=>$value), $msg_val is the value that needs to be selected by default. The function can be written as a static method in a PHP static class, which is more convenient to use. |