如何从数组中删除方括号?

时间:2017-07-07 10:00:14

标签: php codeigniter

代码:

public function get_calendar_data($year, $month)
  {
     $query = $this->db->select('exam_date,exam_name')->from('exam')->like('exam_date',"$year-$month",'after')->get();
     $cal_data = array();
     foreach ($query->result() as $row) 
     {
        $cal_data[substr($row->exam_date,8,2)] = $row->exam_name;
     }
     return $cal_data;
  }

  public function generate($year, $month)
  {

     $this->load->library('calendar', $this->conf);
     $cal_data = $this->get_calendar_data($year, $month);
     print_r($cal_data);
     return $this->calendar->generate($year, $month, $cal_data);
  }

我是codeigniter的新手。在此代码中,当我使用print_r($ cal_data)时,它显示数组([06] =>' AIEEE',[07] =>' JEE')但我想这样数组(06 =>' AIEEE',07 =>' JEE')。那么,我该怎么做呢?请帮帮我。

谢谢

1 个答案:

答案 0 :(得分:0)

此处删除print_r,因为您要返回日历生成

也不确定这是什么$ this-> conf你没有在你的代码上拥有它。

public function generate($year, $month)
{
    $this->load->library('calendar', $this->conf);

    $cal_data = $this->get_calendar_data($year, $month);

    return $this->calendar->generate($year, $month, $cal_data);
}

然后在另一个函数上,例如echo函数"注意这只是一个例子"

public function __construct() 
{
   parent::__construct();
}  

public function index() 
{
    echo $this->generate('2017', '06');
}

public function generate($year, $month)
{
    $this->load->library('calendar', $this->conf);

    $cal_data = $this->get_calendar_data($year, $month);

    return $this->calendar->generate($year, $month, $cal_data);
}