[英]pass array from controller to view in codeigniter
Model: 模型:
Grabs data from mySQL with the value: array['10','5','2']
and puts it in the session data 使用以下值从mySQL抓取数据:
array['10','5','2']
并将其放入会话数据中
Controller: 控制器:
Puts that session data into an array to pass to the view: 将会话数据放入数组以传递到视图:
$fubar = array(
'ex1' => $this->session->userdata('ex1')
);
$this->load->view('view', $fubar);
View: 视图:
echo $ex1;
The view will spit out the array: array['10','5','2']
How do I parse that array to get the individual values (10, 5, or 2)? 该视图将吐出数组:
array['10','5','2']
如何解析该数组以获取单个值(10、5或2)? For example, echo $ex1['1'];
例如,
echo $ex1['1'];
will spit out the first 1 characters: ar
but I want it to return the value 5
会吐出前1个字符:
ar
但我希望它返回值5
I think perhaps I may not be storing the array properly in mySQL, but I'm not sure. 我想也许我可能没有在MySQL中正确存储数组,但是我不确定。
$fubar['ex1'] = $this->session->userdata('ex1');
$this->load->view('view', $fubar);
Now Try 现在尝试
$ex1[0];
$ex1[1];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.