unxposed Posted June 11, 2009 Share Posted June 11, 2009 Okay I think this should be an easy one! If I'm creating an array from a database like so: while ($row = mysql_fetch_array($result)) { $site[$row['group']][$row['title']][name] = $row['name']; $site[$row['group']][$row['title']][colour] = $row['multiple_choice']; $site[$row['group']][$row['title']][shape] = $row['setting']; } How would I then print the value of the group variable in the array $site[$row['group']] or title variable $site[$row['group']][$row['title']]. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/161856-solved-print-array-variable-multidimensional/ Share on other sites More sharing options...
rhodesa Posted June 11, 2009 Share Posted June 11, 2009 is this what you want? print_r($site[$row['group']]); Link to comment https://forums.phpfreaks.com/topic/161856-solved-print-array-variable-multidimensional/#findComment-853973 Share on other sites More sharing options...
unxposed Posted June 11, 2009 Author Share Posted June 11, 2009 Sorry I don't think I was clear. For example if this was added to the array: $site[first_group][first_item][name] = item_name; how would I echo 'first_group', as this will vary (could be first_group, second_group, some_group, any_group etc.). Thanks! Link to comment https://forums.phpfreaks.com/topic/161856-solved-print-array-variable-multidimensional/#findComment-853983 Share on other sites More sharing options...
rhodesa Posted June 11, 2009 Share Posted June 11, 2009 ok...still not 100% clear...do you mean this: <?php foreach($site as $group=>$titles){ print "Group: $group<br>"; foreach($titles as $title=>$data){ print "--Title: $title<br>"; print "----Name: {$data['name']}<br>"; print "----Colour: {$data['colour']}<br>"; print "----Shape: {$data['shape']}<br>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/161856-solved-print-array-variable-multidimensional/#findComment-853987 Share on other sites More sharing options...
unxposed Posted June 11, 2009 Author Share Posted June 11, 2009 Yes exactly what I mean!! Thank you thank you, this method is exactly what I was after! Link to comment https://forums.phpfreaks.com/topic/161856-solved-print-array-variable-multidimensional/#findComment-853989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.