glenelkins Posted October 26, 2006 Share Posted October 26, 2006 HiConsider the following code, this is simply for testing purposes until i get this right.As you can see, i have an array manually setup for testing here called $pops_info which contains ID, NAME, and NO_SITES.Further down I setup an array with field information called $arr, this is going to be used to table generation. The options are: fields (number of fields with headings) direction (verticle table or horizontal) field_headings (this contains another array with the table field headings) field_contents (this i want to contain the contents from the $pops_info array). The next few lines are obviously loops that display the relevant array info, but Im stuck on creating a loop that will display each of the $pops_info by accessing $arr['field_contents'] am i making sense?[code]<?$pops_info['id'][0] = 1;$pops_info['name'][0] = "Name Test";$pops_info['no_sites'][0] = 2; $pops_info['id'][1] = 2;$pops_info['name'][1] = "Name Test 2";$pops_info['no_sites'][1] = 5;// Display$arr = array ( 'fields' => 2, 'direction' => 'vert', 'field_headings' => array ("Company Name","Number Of Sites"), 'field_contents' => array($pops_info));foreach ($arr as $a) { echo $a."<br>";}foreach ($arr['field_headings'] as $fh) { echo $fh . "<br>";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/25166-nested-arrays-question-little-stuck/ Share on other sites More sharing options...
glenelkins Posted October 26, 2006 Author Share Posted October 26, 2006 i figured that the following will display whats in the field_contents array, but how do i put this through a loop?[code]echo $arr['field_contents'][0]['name'][0];echo $arr['field_contents'][0]['name'][1];[/code] Link to comment https://forums.phpfreaks.com/topic/25166-nested-arrays-question-little-stuck/#findComment-114706 Share on other sites More sharing options...
glenelkins Posted October 26, 2006 Author Share Posted October 26, 2006 ahah, we have joy![code]for ($i=0;$i<count($arr['field_contents'][0]);$i++) { echo $arr['field_contents'][0]['name'][$i];}[/code] Link to comment https://forums.phpfreaks.com/topic/25166-nested-arrays-question-little-stuck/#findComment-114709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.