越来越阵列关键的笨
问题描述:
值我在我的控制器下面一行:越来越阵列关键的笨
$data['faq'] = $this->faqModel->get();
此数据印刷使用的print_r
Array
(
[faq] => Array
(
[0] => Array
(
[faqid] => 12
[catid] => 122
[question] => How this CMS works
[question_en] => How this CMS works
[answer] => How this CMS works?
[answer_en] => How this CMS works?
[sorder] => 2
[visible] => 1
)
[1] => Array
(
[faqid] => 8
[catid] => 121
[question] => How does the design cost?
[question_en] => How does the design cost?
[answer] => How does the design cost?
[answer_en] => How does the design cost?
[sorder] => 1
[visible] => 1
)
)
)
我想使用存储在值以下[catid]键,我试图做这样的事情: $ data ['faq'] ['catid']在控制器中获取该值(我想再次使用该值进行选择)但是我得到与此错误消息:未定义的索引:catid
任何人都可以帮助我获得['catid']的价值?
问候,卓然
答
其3维阵列倒带密切存在faq
阵列的两个元素。你必须写的东西是这样的:$data['faq'][0]['catid']
或$data['faq'][1]['catid']
答
您正在访问的阵列的方式是不正确,你缺少的第二个层次的项目指标。用它作为你正在做正确的方法是做
echo $data['faq'][0]['faqid']; //faqid of the first item
然而,这仅会一次一个faqid
,它不是那么有用,当你迭代。所以,一个好方法就是这样。
foreach($data['faq'] as $value) {
echo $value['faqid'];
}
你缺少前CATID $数据指数[ '常见问题解答'] [0] [ 'CATID'] – arma 2012-03-19 10:11:04
感谢ARMA,它现在的作品。 – Zoran 2012-03-19 10:26:26