使用代码对查询执行 foreach


doing a foreach on queries using codeigntier?

我正在尝试使用代码点火器对我的模型进行foreach,但它给了我一个错误并返回结果。

代码如下:

public function read(){
        $questions; //array
        $query = $this->db->get('questions');
        foreach($query->result() as $row){
            $getAnswers = $this->db->get_where('answers', array('question_id'=>$row['question_id]']), 4);
            $questions= $getAnswers;
           }
        return $questions;
     }

这是错误:

致命错误:不能将 stdClass 类型的对象用作数组

row作为对象访问:

$getAnswers = $this->db->get_where('answers', 
                   array('question_id'=>$row->question_id), 4);