gazrobur gazrobur - 1 year ago 100
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;

Answer Source

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

$data = array_merge_recursive($data, $query->result());
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download