Welcome Guest, Not a member yet? Register   Sign In
Appending data to a multidimensional array.
#1

[eluser]jonny68[/eluser]
Hi,

i'm struggling to build a category tree in CI and now i'm facing a new fight Smile

As you can see it loops through the result and the tree == 1 goes fine and build the array $data with the first level, the tree == 2 goes fine and build the 2 level nested under the first but i can't handle how to build the 3rd nested level, tree == 3 never work, i tried a billion things but no luck, maybe it is not possible.. Sad Let me know what you know.. Smile
Code:
foreach ($Q->result() as $row){
                          if($row->tree == 3) {
                          
                            $data[0][9]['children'][$row->parentid]['children'][$row->id]['name'] = $row->name; ///??? How can i add the last nested part of the array to the rest?
// here i put [9] manually cos that's the first key should be modified but like doesn't make sense...
                                
                          } elseif($row->tree == 2) {
                            $data[0][$row->parentid]['children'][$row->id]['name'] = $row->name;
                              
                          } elseif($row->tree == 1) {
                              $data[0][$row->id]['name'] = $row->name;
                     }
}


Messages In This Thread
Appending data to a multidimensional array. - by El Forum - 05-03-2012, 10:28 AM
Appending data to a multidimensional array. - by El Forum - 05-03-2012, 01:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB