robcrozier Posted March 30, 2009 Share Posted March 30, 2009 Hi. I wonder iof anyone can point me in the right direction with this? Basically i have the following array structure: Array ( [GetAllProductGroupCategoriesResult] => Array ( [ProductGroupCategory] => Array ( [0] => Array ( [ProductGroupID] => BVID [ProductGroup] => Books and Videos [CategoryID] => BVBO [CategoryName] => Books ) [1] => Array ( [ProductGroupID] => BVID [ProductGroup] => Books and Videos [CategoryID] => MIP [CategoryName] => MIP ) [2] => Array ( [ProductGroupID] => BVID [ProductGroup] => Books and Videos [CategoryID] => PMUS [CategoryName] => Printed Music ) ) ) ) ... and what i want to do is loop through the array and print out each CategoryName and possibly CategoryID. I just cxant get my head around it as the array is multi dimensional. Can anyone help me with this one? Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/151749-solved-multi-dimensional-array-help/ Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 Something like this: foreach($GetAllProductGroupCategoriesResult AS $key) { foreach($key AS $key2) { echo $key2['CategoryName'] . " => " . $key2['CategoryID']; } } Quote Link to comment https://forums.phpfreaks.com/topic/151749-solved-multi-dimensional-array-help/#findComment-796822 Share on other sites More sharing options...
robcrozier Posted March 30, 2009 Author Share Posted March 30, 2009 Hi Maq. Thanks for your reply, however i'm getting the following error when i use that code. Notice: Undefined index: CategoryName Similar error for CategoryID Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/151749-solved-multi-dimensional-array-help/#findComment-796825 Share on other sites More sharing options...
robcrozier Posted March 30, 2009 Author Share Posted March 30, 2009 Fixed. Just needed one more nested loop. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/151749-solved-multi-dimensional-array-help/#findComment-796828 Share on other sites More sharing options...
Maq Posted March 30, 2009 Share Posted March 30, 2009 Fixed. Just needed one more nested loop. Cheers! Ah yes, sorry about that. I always do multi-array loops wrong in my head. Quote Link to comment https://forums.phpfreaks.com/topic/151749-solved-multi-dimensional-array-help/#findComment-796834 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.