首页 > 代码库 > 追加下拉框的自动生成

追加下拉框的自动生成

/**
 * 下拉选择基础方法
 * @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 =http://www.mamicode.com/= $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 =http://www.mamicode.com/= $id && $selected_value != ‘‘) ? selected="selected" : ‘‘;
        $html .= <option value="http://www.mamicode.com/ . $id . "  . $selected . > . $value_arr . </option>;
    }

    return $html;
}

 

追加下拉框的自动生成