Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6894191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:45:07+00:00 2026-05-27T06:45:07+00:00

I am dealing with two rows of a table, each with nested foreach loops

  • 0

I am dealing with two rows of a table, each with nested foreach loops based on separate arrays. I want to be able to make a value from the first row, available to the second row. Looking at the data below, I want to be able to have access to the values of 3, 1, and 2, and use those values (to determine column widths) in the second array of data.

This is the first data array, used in row 1:

Array
(
[Nov 18, 2011] => Array
    (
        [C] => 3
        [I] => 1
    )
[Nov 22, 2011] => Array
    (
        [C] => 2
    )
)

This is the second data array, used in row 2:

Array
(
[Nov 18, 2011] => Array
    (
        [C] => 107705.5792
        [I] => 44561.52
    )
[Nov 22, 2011] => Array
    (
        [C] => -8992.8352
    )
)

Here is the current table structure for the two rows:

<tr> <!-- ROW 1 -->
<th>f1</th>
<td>f1</td>
<?php foreach($array1 as $a1) { ?>
     <?php foreach ($a1 as $k=>$v) { ?>        
        <td colspan=<?php echo $v ?>>
            <?php echo ($k."_".$v) ?>
        </td>
     <?php } ?>           
<?php } ?>
</tr>
<tr> <!-- ROW 2 -->
<th>f2</th>
<td>f2</td>
<?php foreach($array2 as $a1) { ?>
     <?php foreach ($a1 as $k=>$v) { ?>        
        <td>
            <?php echo ($k."_".$v) ?>
        </td>
     <?php } ?>           
<?php } ?>
</tr>

I think that what needs to happen is that the two arrays need to be combined in some way. I need this structure for my data:

[C] => 107705.5792 - needs to have column width of 3 
[I] => 44561.52 - needs to have column width of 1  
[C] => -8992.8352 - needs to have column width of 2

I hope I have explained this clearly enough. Thanks for any help you can offer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:45:08+00:00Added an answer on May 27, 2026 at 6:45 am

    You can combine each entry from the first array together with the entry from the second array as an array with two values:

    $combined = $first;
    foreach($combined as $date => $vs)
    {
        foreach($vs as $k => &$v)
        {
           $v = array($v, $second[$date][$k]);
        }
    }
    unset($v);
    

    Then you can access both values like this:

    list($a, $b) = $combined['Nov 22, 2011']['C'];
    // $a: 2
    // $b: -8992.8352
    

    Usage:

    ...
    <tr> <!-- ROW 2 -->
    <th>f2</th>
    <td>f2</td>
    <?php foreach($combined as $dates) { ?>
         <?php foreach ($dates as $date=>$v)
               {
                   list($colspan, $value) = $v;
         ?>
            <td colspan=<?php echo $colspan; ?>>
                <?php echo ($date."_".$value) ?>
            </td>
         <?php } ?>           
    <?php } ?>
    </tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have trouble dealing with my for loops now, I'm trying to compare two
I am dealing with several bus routes. I want to fetch the two points
I have rough ideas - like dealing with singular/plural, two or more words/phrases that
When dealing with a collection of key/value pairs is there any difference between using
I'm dealing with a MySQL table that defines the JobName column as UNIQUE. If
I am currently dealing with two devices connected to the I2C bus within an
I'm dealing with two question marks in a single entry website. I'm trying to
I'm often dealing with some interfaces between two systems with data import or data
Consider a beginner dealing with Dependency Injection. We're analyzing two relevant classes in NerdDinner.
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.