在codeigniter视图文件中传递2种类型的数组变量 [英] Passing 2 types of array variables in codeigniter view files

查看:160
本文介绍了在codeigniter视图文件中传递2种类型的数组变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在控制器中有$ data []数组和$ another_data [],我们如何在视图文件中传递这两种类型的数据?条件是codeigniter实现就像$ this-> load-> view('view_page',$ data)

If i have $data[] array and $another_data[] in controller how do we pass both type of data in view files ? provided that codeigniter implementation is like $this->load->view('view_page', $data)

推荐答案

保证数组键在两个数组之间是唯一的,你可以使用array_merge在传递给视图之前合并两个数组。

If you can guarantee that the array keys are unique across the two arrays you can use array_merge to merge the two arrays before passing to the view.

$this->load->view('view_page', array_merge($data, $another_data));

否则,您可以创建一个父数组并将它们存储为子数组。

Otherwise you can create a parent array and store both as subarrays.

$parent_data = array('data' => $data, 'another_data' => $another_data);
$this->load->view('view_page', $parent_data);

这篇关于在codeigniter视图文件中传递2种类型的数组变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆