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
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.