码迷,mamicode.com
首页 > 其他好文 > 详细

追加下拉框的自动生成

时间:2016-12-07 14:08:48      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:foreach   color   type   htm   bsp   amp   code   自动   div   

/**
 * 下拉选择基础方法
 * @param type $selected_value
 * @param type $select_rows
 * @param type $key
 * @param type $value
 * @param type $_first_option
 * @return string 
 */
function select($selected_value, $select_rows, $key, $value, $_first_option = array()) {

    if (count($_first_option) > 0 && is_array($_first_option)) {
        list($first_key, $first_value) = each($_first_option);
        $html = <option value=""  . (($selected_value == $first_key) ? selected="selected" : ‘‘) . > . $first_value . </option>;
    }
    foreach ($select_rows as $select_row) {
        $id = array();
        $value_arr = array();

        if (is_array($key)) {
            foreach ($key as $_key) {
                $id[] = $select_row[$_key];
            }
            //$this->dump($id);
            $id = implode("|", $id);
        } else {
            $id = $select_row[$key];
        }

        if (is_array($value)) {
            foreach ($value as $value_key) {
                $value_arr[] = $select_row[$value_key];
            }
            //$this->dump($id);
            $value_arr = implode(_, $value_arr);
        } else {
            $value_arr = $select_row[$value];
        }

        $selected = ($selected_value == $id && $selected_value != ‘‘) ? selected="selected" : ‘‘;
        $html .= <option value=" . $id . "  . $selected . > . $value_arr . </option>;
    }

    return $html;
}

 

追加下拉框的自动生成

标签:foreach   color   type   htm   bsp   amp   code   自动   div   

原文地址:http://www.cnblogs.com/xs-yqz/p/6140686.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!