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. Link to comment https://forums.phpfreaks.com/topic/283939-build-complex-data-structure-with-array-and-stdclass/ 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. Link to comment https://forums.phpfreaks.com/topic/283939-build-complex-data-structure-with-array-and-stdclass/#findComment-1458463 Share on other sites More sharing options...
patrickhertling Posted November 16, 2013 Author Share Posted November 16, 2013 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 Link to comment https://forums.phpfreaks.com/topic/283939-build-complex-data-structure-with-array-and-stdclass/#findComment-1458553 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? Link to comment https://forums.phpfreaks.com/topic/283939-build-complex-data-structure-with-array-and-stdclass/#findComment-1458574 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()". Link to comment https://forums.phpfreaks.com/topic/283939-build-complex-data-structure-with-array-and-stdclass/#findComment-1458580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.