I am having a foreach loop, inside that data is fetching from mongodb Here is a sample
foreach($result as $document)
{
$response_object = $this->user_model->getdata($document['id']);
}
$response_object holds the mongocursor object of last iteration in this example. I need make $response_object as object variable which has to concatenate the objects in foreach till iteration and store in $response_object.
And why do you need a variable when you can use an array?
$listOfResponses = array();
foreach($result as $document)
array_push($listOfResponses, $this->user_model->getdata($document['id']));