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;
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler