Hi I need to build a table with twig from a php array, I would like to use the array keys as header for each column.
this is the array
Array (
[0] => Array (
[building_code] => 2C
[building_unit_id] => 57
[address] => Via monteverde 45
[name] => Andrea
)
[1] => Array (
[building_code] => 4E
[building_unit_id] => 55
[address] => Via monteverde 45
[name] => Andrea
)
)
This is what I've tried so far
<table>
<thead>
<tr>
{% for titolo in prova|keys %}
<th>{{titolo}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for sub_array in prova %}
<tr>
{% for value in sub_array %}
<td>{{ value }}</th>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
This is the result
0 1
2C 57 Via monteverde 45 Andrea
4E 55 Via monteverde 45 Andrea