我想从$data2['menu_down']
获取价值以发送给我的观点,但我总是得到最后一个值$data2
public function index(){
$data['menu'] = $this->M_home->tampil_menu_utama();
foreach ($data['menu'] as $menus) {
$idmenu = $menus->menuid;
$data2['menu_down'] = $this->M_home->tampil_menu_down($idmenu);
}
$this->load->view('head',array_merge($data,$data2));
$this->load->view('home');
$this->load->view('foot');
}
答案 0 :(得分:-1)
您需要将$data2
作为数组;
public function index(){
$data['menu'] = $this->M_home->tampil_menu_utama();
$data2 = array(); //initialize your variable with array;
foreach ($data['menu'] as $menus) {
$idmenu = $menus->menuid;
$data2['menu_down'][] = $this->M_home->tampil_menu_down($idmenu);
}
$result['menu_down']=array_merge($data,$data2);
$this->load->view('head',$result);
$this->load->view('home');
$this->load->view('foot');
}