Php Codeigniter:解析视图中的数组数据
我正在尝试获取POST数据,并通过它来使用这样的控制器进行查看Php Codeigniter:解析视图中的数组数据,php,arrays,codeigniter,Php,Arrays,Codeigniter,我正在尝试获取POST数据,并通过它来使用这样的控制器进行查看 $data['data']=$this->home->fetch_all_posts($this->news); $this->load->view('home',$data); 在我看来,当我打印($data)时,这就是我得到的 Array ( [0] => Array ( [post] => stdClass Object
$data['data']=$this->home->fetch_all_posts($this->news);
$this->load->view('home',$data);
在我看来,当我打印($data)时,这就是我得到的
Array
(
[0] => Array
(
[post] => stdClass Object
(
[id] => 65
[date] => 2016-07-08
[title] => title of the news
[content] => content of the news
[type] => news
)
[attachments] => stdClass Object
(
[id] => 2
[attachment_id] => 65
[type] => news
[path] => C:/wamp/www/school/ci/images/Jellyfish22.jpg
)
)
)
现在,当我尝试获取此值并打印它不起作用时,请帮助我如何打印这些值codeIgniter将把
$data
的值转换为它自己的变量。因此,$data['foobar']
在视图中变为$foobar
。您使用的$data['data']
可能会令人困惑和含糊不清,我建议您使用更具体的名称。试试这样的方法。
if (!empty($data)) {
foreach ($data as $row)
{
$row['post']->id;
$row['post']->title;
$row['attachments']->id;
$row['attachments']->attachment_id;
}
}
这应该是你所需要的
$array = array(
array('post'=> array(
'id' => 65,
'date' => '2016-07-08',
'title' => 'title of the news',
'content' => 'content',
'type' => 'news'
),
'attachments' => array(
'id'=>2,
'attachment_id' => 65,
'type'=> 'new',
'path' =>'C:/wamp'
))
);
foreach ($array as $key => $value) {
print_r($value['post']['id']);
}
…并打印它不起作用
。好的,会发生什么?请始终对给出的答案做出响应,用绿色支票标记,如果您觉得有帮助,请进行投票