I have the following array
Array
(
[Germany] => Array
(
[Channels] => Array
(
[0] => Google Ads
[1] => LinkedIn Ads
[2] => E-Mail-Marketing
)
[Tools] => Array
(
[0] => CRM
)
)
[USA] => Array
(
[SalesTools] => Array
(
[0] => Pipedrive
[1] => Salesforce
)
)
)
and want to show it in a table like this:
<table>
<tr>
<th>Region</th>
<th>Costcenter</th>
<th>Costcenter_item</th>
</tr>
<tr>
<td rowspan='4'>Germany</td>
<td rowspan='3'>Channels</td>
<td>Google Ads</td>
</tr>
<tr>
<td>Linkedin</td>
</tr>
<tr>
<td>Email Marketing</td>
</tr>
<tr>
<td rowspan='1' >Tools</td>
<td>CRM</td>
</tr>
<tr>
<td rowspan='2'>USA</td>
<td rowspan='2'>Sales Tools</td>
<td>Pipedrive</td>
</tr>
<tr>
<td>Salesforce</td>
</tr>
</table>
But I get absolutely confused about the rowspans. I tried using backtracking on the array to count the "leaves" but I couldnt make it work. How can I get the correct rowspan number while building this html table programmatically with php?