💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
` ~~~ /** * @param $data 数据源 * @param $name select name值 * @param int $selected_id 选中的值 * @param string $required 是否必选 空可不选 ,required 必选 * @param string $filter layui的filter属性 * @param string $show_field 显示的字段 * @param string $val_field 值的字段 * @param string $msg 提示消息 * @author: LuckyHhy <jackhhy520@qq.com> * @date: 2020/3/23 * @name: make_options * @describe: 数据源转layui-select */ function make_layui_select($data,$name, $selected_id = 0 ,$show_field = 'name', $val_field = 'id',$required="",$filter="",$msg="") { $html = '<select name="'.$name.'" lay-verify="'.$required.'" lay-search="" lay-filter="'.$filter.'" lay-verType="tips" lay-reqText="请选择'.$msg.'" ><option value="">【请选择'.$msg.'】</option>'; $show_field_arr = explode(',', $show_field); //dump($data); if (is_array($data)) { foreach ($data as $k => $v) { $show_text = ''; if (is_array($v)) { foreach ($show_field_arr as $s) { $show_text .= $v[$s] . ' '; } $show_text = substr($show_text, 0, -1); $val_field && $k = $v[$val_field]; } else { $show_text = $v; } $sel = ''; if ($selected_id && $k == $selected_id) { $sel = 'selected'; } $html .= '<option value = ' . $k . ' ' . $sel . '>' . $show_text . '</option>'; } }else{ $html .= '<option value = "0">data不是数组</option>'; } $html.='</select>'; echo $html; } ~~~ ` ### 调用 ` {$data|make_layui_select=$name,$selectId,$show_name,$show_field,$value_id,$required,$filter,$msg} `