3v4l.org

run code in 300+ PHP versions simultaneously
<?php $results = [ (object)['id' => 1, 'uid' => 20, 'bet' => '1'], (object)['id' => 2, 'uid' => 20, 'bet' => '2'], (object)['id' => 1, 'uid' => 21, 'bet' => 'X'], (object)['id' => 2, 'uid' => 21, 'bet' => '1'], (object)['id' => 1, 'uid' => 22, 'bet' => 'X'], (object)['id' => 2, 'uid' => 22, 'bet' => 'X'] ]; $group = null; foreach ($results as $row){ if ($row->uid !== $group) { if ($group !== null) { echo "</div>\n"; } echo "<div class=\"kupon_gruppe\">Group - $row->uid:\n"; } echo "\t<div class=\"dagens_kampe_kupon\">ID: $row->id - Bet: $row->bet</div>\n"; $group = $row->uid; }; echo "</div>";
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13, 8.1rc1 - rc3
<div class="kupon_gruppe">Group - 20: <div class="dagens_kampe_kupon">ID: 1 - Bet: 1</div> <div class="dagens_kampe_kupon">ID: 2 - Bet: 2</div> </div> <div class="kupon_gruppe">Group - 21: <div class="dagens_kampe_kupon">ID: 1 - Bet: X</div> <div class="dagens_kampe_kupon">ID: 2 - Bet: 1</div> </div> <div class="kupon_gruppe">Group - 22: <div class="dagens_kampe_kupon">ID: 1 - Bet: X</div> <div class="dagens_kampe_kupon">ID: 2 - Bet: X</div> </div>

preferences:
31.26 ms | 461 KiB | 5 Q