Skip to content
Advertisement

HTML table in php foreach loop where the cell data is only populated if an element is equal to the table column head name

I have created my column headers in my table by using:

JavaScript

$round is:

JavaScript

This results in exactly what I want because $round won’t always result in the same number of columns.

The data I want in the table row beneath those headers needs to be only those items that contain the column header’s name.

Let’s say the column headers are: | -7 | -6 | -5 | -4 | -3 | -2 | -1 | 1 | 2 | 3 | 4 | 5 | 6 | based on the foreach loop above.

I used the following to then populate my first column in the next row:

JavaScript

And while it works, it’s only because I know the header of my first column in the table is -7. I’m trying to figure out how to only display those items that are equal to my column header to display in the following row based on the column header so that I can then do another foreach loop to display the remainder of my table. So basically, instead of -7 that I have above, what do I need to do? I’m completely drawing a blank.

$match[‘match’][’round’] is what is equal to the column headers. And a small sample $matches is below in case that helps.

JavaScript

I’ve attempted to reindex the array by using:

JavaScript

Desired output is like this: enter image description here

Advertisement

Answer

You can use a dictionary to store all the matches based on the rounds:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement