I have following array
[
{
id: 1,
group_name: 'usa',
state : 'San Francisco'
},
{
id: 2,
group_name: 'usa',
state : 'Texas'
},
{
id: 3,
group_name: 'usa',
state : 'North Carolina'
}, {
id: 4,
group_name: 'aus',
state : 'Darwin'
},
{
id: 5,
group_name: 'aus',
state : 'Melbourne'
},
{
id: 6,
group_name: 'usa',
state : 'Perth'
}
]
I want to print as following:
Group Name: USA
State: San Francisco
State: Texas
State: North Carolina
Group Name: AUS
State: Darwin
State: Perth
State: Sydney
I tried following in twig but lacked in logic
{% for place in places %}
<tr>
<td>{{ dump(place.getGroupName()) }}</td>
</tr>
<tr>
<td>{{ place.state}}</td>
</tr>
{% endif %}
In the loop I want to put the country above the list of states. In the list of states the country must be top following by the states and same with the other countries as well.