codeigniter - Generate multi-dimensional array in Controller, how to call it in view
PHP中文网
PHP中文网 2017-05-16 16:43:40
0
1
284

Generally we use one-dimensional arrays, for example:
$data['regions'] = $this->index_model->get_region();
Then use $regions directly in the view to make data calls.
But what if I want to generate a multidimensional array, for example:
$data[1]['streets'] = $this->index_model->get_street(1,1);
$data[2]['streets'] = $this->index_model->get_street(2,1);
In this way, how to call it in the view, thank you everyone~

PHP中文网
PHP中文网

认证高级PHP讲师

reply all (1)
Ty80

Place the contents of a multidimensional array into an element of the array passed to the$this->load->view()method, like this:

$data['streets'][1]['streets'] = $this->index_model->get_street(1,1); $data['streets'][2]['streets'] = $this->index_model->get_street(2,1);

Then pass the$dataarray to the$data数组传递给$this->load->view()method, like this:

$this->load->view('...', $data);

After that you can call it like this in the view:

 
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!