I have a HTML table with the below format: As you can see, the first Header 1 has one Row 1 associated with it. The second Header 2 has two rows - Row 2, Row 3 associated with it. Header 3 has Row 4, Row 5, Row 6 associated with it.
<table>
<thead>
<tr>
<th>Header 1</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 1
</td>
</tr>
</tbody>
<thead>
<tr>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 2
</td>
</tr>
<tr>
<td>
Row 3
</td>
</tr>
</tbody>
<thead>
<tr>
<th>Header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>
Row 4
</td>
</tr>
<tr>
<td>
Row 5
</td>
</tr>
<tr>
<td>
Row 6
</td>
</tr>
</tbody>
I want to use the PHP Simple HTML Dom parser to get the following data:
Header 1, Row 1
Header 2, Row 2, Row 3
Header 3, Row 4, Row 5, Row 6
When I use the parser to get the tags, all of them are stored in one array. All other tags are stored in another array when I do the foreach loop. How do I preserve the association of the headers with the rows when I am looping?