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 9273393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:06:16+00:00 2026-06-18T16:06:16+00:00

I am trying to figure out how to parse an associative array I have

  • 0

I am trying to figure out how to parse an associative array I have constructed from database data in such a way that I can produce the html table layout that I’m looking for.

Associative array structure is as follows:

Array
(
  [2013] => Array
    (
        [1] => Array
            (
                [Total] => Array
                    (
                        [validleads] => 7327
                        [conversions] => 9856
                        [bookings] => 2449
                    )
                    ... more types for this week
                 [PPC] => Array
                    (
                        [validleads] => 884
                        [conversions] => 1109
                        [bookings] => 605
                    )
            )
          .. more weeks for 2013
    )
  [2012] => Array
    (
        [1] => Array
            (
                [Total] => Array
                    (
                        [validleads] => 9423
                        [conversions] => 12459
                        [bookings] => 2629
                    )
                [PPC] => Array
                    (
                        [validleads] => 955
                        [conversions] => 1237
                        [bookings] => 601
                    )
    )
)

So, there is one global array ($data) which contains an array for each year and in the arrays for each year there is an array for each week of the year which in turn has an array of figures for that week plus a totals array.

Table structure ideally would be

| Week | Total 2013 | Total 2012 | PPC 2013 | % PPC 2013  |  PPC 2012  | % PPC 2012 |  Other types 2013  | % Other types 2013 | Other types 2012 | % Other types 2012  
|  01  |    7327    |    9423    |   884    |   12.06%    |    955     |    10.13%  |                    |                    |                  |                              

The percentages are just worked out by taking the figure for the that week in the year and dividing it by the total for that week of the year multiplied by 100.

The table layout I want to produce is to generate one table row per week of the year with the total for that week in each year aswell as the total for each type in that week each year and the percentage this total is for the overall total of the week for that year….

Sorry if that’s complicated….

Problem is I just can’t think how to produce what I want in HTML table format.

I know some foreach‘s are required but that’s as far as I get to.

  • 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-18T16:06:18+00:00Added an answer on June 18, 2026 at 4:06 pm

    Something like this you’d need a little work basically you’ll have to lay out your table a little differently for it to work/look right but should be doable. Code below isn’t perfect but hopefully will help you get your head around the problem.

    for ($i=0;$i<count($data);$i++) {
         //initial loop for year
        echo "Year = ".$data[$i]."<br />";
         for ($z=0;$z<count($data[$i]);$z++) {
         //secondary loop for year
         echo "Week =".$data[$i][$z]."<br />";
         //no need to loop through final array if its always jsut total and ppc if its variable on the final loop another for will be needed though
        echo "Totals: ".$data[$i][$z]['Total']['validleads']." etc etc";
        echo "Totals: ".$data[$i][$z]['PPC']['validleads']." etc etc";
    
        }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out a way to parse strings that contain about 3-4
I'm trying to figure out a way to parse out a base64 string from
I'm trying to figure out a way to parse out a base64 string from
I'm trying to figure out how to better parse lines of text that have
I'm trying to access the http://s3.amazonaws.com/commoncrawl/parse-output/segment/ bucket with boto. I can't figure out how
Hello there im trying to figure out how i can parse RSS feeds with
I'm trying to figure out how to parse the <current></current> values from the first
I'm trying to figure out how to use lxml to parse the xml from
I'm still trying to figure out WebSockets. I'm sending over data from the javascript
I'm trying to figure out a way to parse the $ and , out

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.