in my mysql db
I got the following data:
row value
--------------
|row1| 12 |
--------------
|row1| 13 |
--------------
|row2| 15 |
--------------
which I transform to the following php
array($myarray
):
[arr]=>
array(2) {
["row1"]=>
array(2) {
[0]=>
int(12)
[1]=>
int(13)
}
["row2"]=>
array(1) {
[0]=>
int(15)
}
}
which I display with the following code in twig:
{% for key, value in myarray %}
<tr>
<td>{{key}}</td>
<td>{{value|join(', ')}}</td>
</tr>
{% endfor %}
so it looks like the following:
---------------
|row1| 12, 13 |
---------------
|row2| 15 |
---------------
My problem is that when the values for row1
and row2
are equal I need to show them in one table row, like the following (say that values for row2
are also 12 and 13 instead of 15):
---------------------
|row1, row2| 12, 13 |
---------------------
I tried to do that with twig variables like this:
{% set inc = 0 %}
{% for key, value in myarray %}
{% set foo ~ inc = [key, value] %}
{% set inc = inc + 1 %}
...table html here
{% endfor %}
but still cannot join the rows in case arrays for 'row1' and 'row2' are equal. Any ideas how to do that? (There may be more than 2 'row1' and 'row2' in resulting array). Thank you.