CodeIgniter Forums
array is stripped when put foreach - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: array is stripped when put foreach (/thread-40567.html)



array is stripped when put foreach - El Forum - 04-12-2011

[eluser]Unknown[/eluser]
Hello!
I want to make "categories" and their "subcategories" - which I made in pure PHP but with CI I have some troubles.

I have one method get_cat() - which takes the categories, and one method get_subcat($sub) which takes the subcategories.
get_cat() gives me the all info for the categories and I pass it and use only category_id in get_subcat. Well, here is some code:

$data['cat'] = $this->Dbase->get_cat();
//moment 1
foreach($data['cat'] as $cat)
//moment 2
$data['sub'] = $this->Dbase->get_subcat($cat['category_id']);

moment 1 - all categories are there (print_r($data['cat']))
moment 2 - only the first category is there => only 1 id is passed to get_subcat and I get subcategories only for the first cat (print_r($cat))

I hope you understood and can help) Thanks a lot in advance.