$result is an array that looks like this:
Array (
[0] => stdClass Object (
[Key_1] => a
[Key_2] => 10
)
[1] => stdClass Object (
[Key_1] => b
[Key_2] => 10
)
[2] => stdClass Object (
[Key_1] => c
[Key_2] => 20
)
)
How can I echo $result in a foreach loop grouped by [Key_2] wrapped in a div like
<div class="new_Key_2">
Key_2: 10
------------
Key_1: a
Key_1: b
</div>
<div class="new_Key_2">
Key_2: 20
------------
Key_1: c
</div>
I know how to open the div by checking if [Key_2] has changed, but not how to close it before a new [Key_2] comes along.