gpt4 book ai didi

php - 传递多个数组以在 codeigniter 中查看

转载 作者:可可西里 更新时间:2023-10-31 23:55:39 24 4
gpt4 key购买 nike

我的模型是这个,,,两个函数view和spl

 function view(){

$result = $this -> db -> get('tb_ourcity');
return $result->result_array();

//$query = $this->db->query('SELECT * from `adds`');
//return $query->result_array();
}


function spl(){

$result2 = $this -> db -> get('td_spei');
return $result2->result_array();

//$query = $this->db->query('SELECT * from `adds`');
//return $query->result_array();
}

我的 Controller 看起来像这样

    public function index()
{
$data['result']=$this->load_city->view();
$data2['result']=$this->load_city->spl();
$this->load->view('home_view',$data);
}

我有两个名为 $data 和 $data2 的数组..

我想在 home_view 中同时使用这两个数组。那么如何在单个 View 中传递这两个数组

最佳答案

现在你传入你的 View $result 只包含 $this->load_city->spl();

的数据
public function index() 
{
$data['result']=$this->load_city->view();
$data2['result']=$this->load_city->spl();
$this->load->view('home_view',$data);
}

你可以像这样传递两个变量

METHOD 1相同的变量名更改键

public function index() 
{
$data['data1']=$this->load_city->view();
$data['data2']=$this->load_city->spl();
$this->load->view('home_view',$data);
}

方法 2 合并你的数组

public function index() 
{
$data['data1']=$this->load_city->view();
$data2['data2']=$this->load_city->spl();
$new_array = array_merge($data,$data2);
$this->load->view('home_view',$new_array );
}

如果你想创建快捷方式,直接在方法中添加即可

$this->load->view('home_view',array_merge($data, $data2));

关于php - 传递多个数组以在 codeigniter 中查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36466644/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com