I have created a form with 3 rows, each row have 5 columns, and each column contain 3 input box as below screen shot.

I would like to submit this form and generating a table. The structure of the table will determine by the form's data.
For example:
- If I submit the form as below:

It will create a table like this:

(two rows, first row have two columns and second row have one column)
I suppose I need this write a huge of if then else code for this situation, do someone have an idea on writing this logic? Prefer to write it simple/tiny.
Welcome to discuss it.