制作对象并在codeigniter视图上传递它

i have a query from my model. Now in my controller, the query is inside the loop, now i have two results of objects from my query. How can i make it only one object to be passed in my view?

Here is my code:

public function graph_diagnose() {
       $diagnosis = $this->input->post('selectdiagnosis');
       for ($i = 0; $i < count($diagnosis); $i++) {
            $diagname = $this->Adminreport_model->getDiagName($diagnosis[$i]);
            echo json_encode($diagname);
       }
    }

now i have a result from my query that is stored in $diagname and it consist of two rows inside every query.

Here is the result of echo json_encode:

 array(1) {
  [0]=>
  object(stdClass)#23 (2) {
    ["diagnosis"]=>
    string(8) "Headache"
    ["diagnosis_id"]=>
    string(1) "1"
  }
}
array(1) {
  [0]=>
  object(stdClass)#24 (2) {
    ["diagnosis"]=>
    string(10) "Sakit Kaau"
    ["diagnosis_id"]=>
    string(1) "2"
  }
}

now what i want is to make it as one object to be json encode. where i want an output like this:

 array(1) {
  [0]=>
  object(stdClass)#23 (2) {
    ["diagnosis"]=>
    string(8) "Headache"
    ["diagnosis_id"]=>
    string(1) "1"
  }
  [1]=>
  object(stdClass)#23 (2) {
    ["diagnosis"]=>
    string(10) "Sakit Kaau"
    ["diagnosis_id"]=>
    string(1) "2"
  }
}

Define an array to store the result:

$diagnames = [];

Inside the for loop:

$result = $this->Adminreport_model->getDiagName($diagnosis[$i]);
$diagnames = array_merge($diagnames, $result);

But I am wondering why your getDiagName() method is returning an array?