patrickhertling Posted November 15, 2013 Share Posted November 15, 2013 Hi.I would like to build a complex data structure in a foreach bucle and return it after foreach ($array as $row) { // Here we get groupname and item_info for each row. } I want an array of groups(stdClass). Each group has info, and a list of items(stdClass). array( stdClass Group_1 ( info list = array ( stdClass item_1 ( info ) stdClass item_2 (..) ... ) ) ... stdClass Group_n (...) ) Any help to build this would be apreciated. Thank you. Quote Link to comment Share on other sites More sharing options...
requinix Posted November 15, 2013 Share Posted November 15, 2013 Would certainly help to know more than just // Here we get groupname and item_info for each row. Quote Link to comment Share on other sites More sharing options...
patrickhertling Posted November 16, 2013 Author Share Posted November 16, 2013 (edited) Hehe, sorry about that. Please let me explain again: We have an array of stdClass elements: array(element_1, element_2, ..., element_n) Each element is like: element_k : {order: int, name: "name", group_name: "name", group_order: int} Ok. Now I want to build an array / stdClass based data structure like followes: array:[group_1 : {name : "name", order : int, items : [ item_1 : {name : "name", order : int }, ... item_n : {...} ] }, ... group_n : {...} ] I was thinking doing it in a loop, but maybe there is a better way. Thank you very much for your time. Regards Patrick Edited November 16, 2013 by patrickhertling Quote Link to comment Share on other sites More sharing options...
ignace Posted November 16, 2013 Share Posted November 16, 2013 Where does item_1, .., item_n come from? Quote Link to comment Share on other sites More sharing options...
patrickhertling Posted November 16, 2013 Author Share Posted November 16, 2013 I dont think it matters, but from a database query. Its a joomla site and there is a function called "loadObjectList()". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.