试图将数据作为对象数组返回,但在php中获取数组对象的数组

时间:2018-05-29 11:09:05

标签: php json codeigniter

控制器

    $activity_session = array();

    foreach($activities_by_category as $activity)  
    {
        $activity_session[] =  $this->users_model->search_sessions_by_activity($activity->activity_id);
    }

模型

    function search_sessions_by_activity($activity_id){

      $this->db->where('activity_by_id',$activity_id);
      $query = $this->db->get('activity_session');  
      return $query->result(); 
    }

将json对象作为数组

enter image description here

1 个答案:

答案 0 :(得分:0)

使用

更改模型
    function search_sessions_by_activity($activity_id){
    $this->db->where('activity_by_id',$activity_id);
    $query = $this->db->get('activity_session');  
    return $query->result_array(); 
    }

希望它能够正常运作。