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

时间:2017-02-26 03:04:20

标签: php codeigniter

我有这个功能

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

    return $years;      
}

在我的控制器上,我发送到视图

$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);

然后在视图上

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

视图中的选项值如何显示1到72之间的数字,这是错误的。

  

问题如何确保选项值显示年份

enter image description here

1 个答案:

答案 0 :(得分:1)

array_merge_recursive 更改为 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;      
}

或者只是将它们加在一起。

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