Skip to content
Advertisement

php dynamic table from muldimentional array

can you give me idea how to implement this idea for “dynamic” html table. I have an array

JavaScript

Now from the keys ‘label’ im creating the table columns

JavaScript

The problem is how to put ‘fname’ keys in the first column, ‘lname’ in the second and ‘description’ in the third.

With this part of code im trying to put the data in all columns

JavaScript

Also my idea is not to hard code array keys for multiple usage(except label and data).

Advertisement

Answer

First I would remap the data to process it in loops.

JavaScript

Now print out the labels with the headline.

JavaScript

Iterate through the rows and create the HTML.

JavaScript

This gives a table like below

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