douli1306 2017-02-26 03:04
浏览 39
已采纳

未在form_dropdown选项值Codeigniter中显示的年份

I have this function

public function year() {
    $years = array_merge_recursive(
        array('' => 'Please Select'),
        array_combine(range(date("Y"), 1945), range(date("Y"), 1945))
    );

    return $years;      
}

And on my controller I send to view like

$this->data['byear'] = $this->birthday->year(); 

if ($this->input->post('bd3')) {
    $this->data['bd3'] = $this->input->post('bd3');
} else {
    $this->data['bd3'] = '';
}

$this->data['children'] = array(
    'common/header',
    'common/footer',
    'common/navbar' 
);

$this->load->render('account/register', $this->data);

And then on the view

<?php echo form_dropdown('bd3', $byear, $bd3, array('class' => 'form-control', 'id' => 'birthday'));?>

How ever the option value on view displays numbers from 1 to 72 which is wrong.

Question How can I make sure the option value displays the YEARS?

enter image description here

  • 写回答

1条回答 默认 最新

  • dtoq41429 2017-02-26 06:40
    关注

    Change array_merge_recursive to array_replace_recursive

    public function year() {
        $years = array_replace_recursive(
            array('' => 'Please Select'),
            array_combine(range(date("Y"), 1945), range(date("Y"), 1945))
        );
    
        return $years;      
    }
    

    Or just add them together.

    public function year() {
            $years = array('' => 'Please Select') + array_combine(range(date("Y"), 1945), range(date("Y"), 1945));
            return $years;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 VBA-JSON中文乱码报错
  • ¥50 dac adc的检定规程
  • ¥20 MIT控制器能控制不稳定系统吗
  • ¥15 公司代码X对业务伙伴X无效,处理方法?
  • ¥15 微信内链接跳转到浏览器打开怎么实现
  • ¥15 三角波可以直接加施密特电路整形到矩形波吗实物
  • ¥15 html,php,在使用html请求php文件时发生了错误,无法请求到php文件读取数据库并用javascript进行数据显示,刷新
  • ¥15 touchsocket udp组播
  • ¥20 MAC怎么安装Silverlight 插件?以及安装了怎么启用
  • ¥15 gis系统开发出现命名空间“ESRI.ArcGIS”中不存在类型或命名空间名“Analyst3D”报错