[eluser]jcargilo[/eluser]
Hi there, new to CI/PHP and could use some help building a multi-dimensional array from db queries. In a nutshell, I'm looking to obtain a list of categories into an array, and then within that category array I would like to obtain category info AND an array of assigned items. The format I'm trying to achieve is this:
Code:
Array
(
[0] => Array
(
[id] => 1
[title] => Category 1
[rank] => 1
[item] => Array
(
[id] => 1
[title] => Item 1
[rank] => 1
)
)
...
)
Now, I am stumped as to how to embed the second Array into the first. I have two methods in my Model to obtain this information:
get_categories and
get_items_by_category_id. I tried doing something like the following from my controller to no avail:
Code:
$data['categories'] = $this->categories_model->get_categories();
foreach ($data['categories'] as $category) {
$category['items'] = $this->items_model->get_items_by_category_id($category['id']);
}
I don't believe the $category variable is being passed by reference, so that's one issue. However, even replacing that with the original array doesn't have any affect. I know I'm going about this wrong, so I'd greatly appreciate some assistance.