Can you please tell us how to use your function in CodeIgniter in the template itself? I understand that this is not beautiful and not correct, but otherwise you will have to disassemble an array of this type:
---- category 2
----- category 3
------- category 5
And then again to collect in the same form, but with the addition of additional. key to each array. Tried to register
$this->myfunct($id) did not work.