如何从数组中删除括号

时间:2018-02-06 09:53:01

标签: php arrays codeigniter

如何删除括号并从数组中插入逗号(,)?

我的代码输出:($ var_array)

Array ( [06] => Body Weight Squat [04] => Body Weight Squat ) 

期望:($ var_new_array)

array(
    06  => 'Body Weight Squat',
    04  => 'Body Weight Squat' 
)

代码:

$data['year'] = $year; 
$data['month'] = $month;  
$query = $this->daysmodel->fetch_exercises_byForDate($year.'-'.$month.'-');
$data['query']=$query; 
$array[] = [];  
foreach ($query as $row) {
    $date=$row->for_date; 
    $array[date('d', strtotime($date))] = $row->menu_name  ;
} 
$newArray= $this->array_flatten($array); 
print_r( $newArray);// Array ( [06] => Body Weight Squat [04] => Body Weight Squat )  
$this->load->view('calender/myCalender', $data);

我正在尝试这个Passing Data to your Calendar Cells

1 个答案:

答案 0 :(得分:0)

只需删除

$array[] = [];

并直接使用$array[]

它肯定会有用。