首先原谅我,我是codeigniter框架的初学者。我想在视图中显示父数组的所有子内容。我假设我的数据检索部分已经完成,现在我需要知道如何使用foreach获取值。我用foreach,但我得到错误(非法字符串偏移量)。这是我得到我的页面的var_dump值。查看codeigniter中的数据
array(1) {
["post"]=>
array(6) {
["post_id"]=>
string(2) "52"
["status"]=>
string(29) "This is a test status update."
["user"]=>
string(1) "1"
["time"]=>
string(19) "2015-02-05 19:47:42"
["modified"]=>
string(19) "0000-00-00 00:00:00"
["comment"]=>
array(2) {
[0]=>
array(3) {
["comment_id"]=>
string(1) "3"
["comment"]=>
string(22) "This is a test comment"
["comment_datetime"]=>
string(19) "2015-02-06 08:36:15"
}
[1]=>
array(3) {
["comment_id"]=>
string(1) "5"
["comment"]=>
string(11) "sdfsdfsdfds"
["comment_datetime"]=>
string(19) "2015-02-06 09:33:25"
}
}
}
}
我已经通过得到的数据是这样的尝试:
<?php
foreach($post as $data){
$data['status'];
$data['post_id'];
}
?>
但是,当我做到这一点我得到非法串偏移错误消息。
尝试在foreach循环中打印值 – john 2015-02-06 07:30:33