gazrobur gazrobur - 2 months ago 9x
PHP Question

How to merge array with result in Codeigniter?

I have this code in Codeigniter, but somehow array_merge does not want to work, how is it possible to merge array to the result? please help me, Thanks.

$categories = $this->get_categories();

$data = array();

foreach ($categories as $index) {
$this->db->where('category', $index);
$query = $this->db->get();

array_merge_recursive($data, $query->result());


return $data;


You need to save the result of array_merge_recursive() to the $data string:

$data = array_merge_recursive($data, $query->result());