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

  • SEARCH
  • Home
  • 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 8805739
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:56:36+00:00 2026-06-14T01:56:36+00:00

I just asked a question about associative arrays and using foreach to retrieve the

  • 0

I just asked a question about associative arrays and using foreach to retrieve the data but I am struggling to think of a way to build the table I want from this data structure.

I have an array $dailytotals of the form

Array
(
    [204] => Array
    (
        [1] => Array
           (
               [leads] => 9
           )

        [2] => Array
            (
                [leads] => 15
            )

    )

    [200] => Array
    (
        [1] => Array
            (
                [leads] => 7
            )

        [2] => Array
            (
                [leads] => 16
            )

        [3] => Array
            (
                [leads] => 5
            )
)

So I could have any number of sub arrays in the main array with any number of sub arrays within that.

So far I’ve managed the grand task of building my table header:

<table>
    <tr>
        <th>Clinic</th>

        <?php
         // get unique columns - not all clinics will have leads for all columns
        $columns = array();
        foreach ($dailytotals as $key => $arr) {
            $columns = array_unique(array_merge($columns, array_keys($arr)));
        }

        foreach ($columns as $index => $campaignid) {
           echo '<th>' . $campaignid . '</th>';
        }
       ?>
    </tr>

But I am completely stuck now how to build the table body.

The structure I want to build is:

Clinic  |  1  |  2  |  3  |
___________________________
204     |  9  |  15 |  0  |
200     |  7  |  16 |  5  |
  • 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-06-14T01:56:37+00:00Added an answer on June 14, 2026 at 1:56 am

    You need some nested loops. Try this:

    <table>
        <tr>
            <th>Clinic</th>
    
            <?php
             // get unique columns - not all clinics will have leads for all columns
            $columns = array();
            foreach ($dailytotals as $key => $arr) {
                $columns = array_unique(array_merge($columns, array_keys($arr)));
            }
    
            foreach ($columns as $index => $campaignid) {
               echo '<th>' . $campaignid . '</th>';
            }
           ?>
        </tr>
        <?php
            foreach($dailytotals as $clinic => $data)
            {
                echo '<tr>';
                echo '<td>'.$clinic.'</td>';
                foreach($columns as $column)
                {
                    echo '<td>';
                    echo isset($data[$column]) ? $data[$column]['leads'] : 0;
                    echo '</td>';
                }
                echo '</tr>';
            }
    
        ?>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just asked a question about this but I want to go at it
I just asked a question that helps about using generics (or polymorphism) to avoid
I have asked a question about how to retrieve data from different tables in
I've just asked question about Task but realized that I actually want to ask
I asked a simialr question earlier about using jquery and hashtags but what I
I know I've just asked a question about this, but I cannot figure out
I just asked a question about ordering but it was only the first part
I just asked this question about using a regular expression to allow numbers between
Just asked a question about linking Boost libraries in the make file. Thanks to
I've just asked a question about an hour ago, while waiting for replies, I've

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.