Jump to content

Nested Arrays Question - little stuck!


glenelkins

Recommended Posts

Hi

Consider 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

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.