I am using a community in Codeigniter with phpbb. I don't know why but i am getting this error
A PHP Error was encountered
Severity: Notice
Message: Undefined index: 43
Filename: models/forum.php
Line Number: 287
Here is that function
public function forumGetter() {
$rez = $this->db->select('*')->from('phpbb_forums')->where('forum_id != 75')->where('parent_id != 75')->get();
$ret = array();
$foruminfo = $this->forumInfo();
foreach ($rez->result_array() as $k=> $v) {
$x = $v;
$x['usercount'] = intval($foruminfo[$v['forum_id']]['usercount']);
$ret[$v['parent_id']][] = $x;
}
return $ret;
}
and line 287 is
$x['usercount'] = intval($foruminfo[$v['forum_id']]['usercount']);
where i am wrong or which kind of error is this?
Update this line:
$x['usercount'] = intval($foruminfo[$v['forum_id']]['usercount']);
To:
$x['usercount'] = isset($foruminfo[$v['forum_id']]) && isset($foruminfo[$v['forum_id']]['usercount']) ?
intval($foruminfo[$v['forum_id']]['usercount']) : 0;
The error is; you are trying to load an array value by the key 43
, i.e. $foruminfo[$v['forum_id']][43]
and you get that error when a value doesn't exist by the specified key. So, best option is to use isset() to assert before you use the key on the array.