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) { echo "<div class=\"kupon_gruppe\">Group - $row->uid:</div>\n"; } echo "<div class=\"dagens_kampe_kupon\">ID: $row->id - Bet: $row->bet</div>\n"; $group = $row->uid; };
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 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> <div class="dagens_kampe_kupon">ID: 1 - Bet: 1</div> <div class="dagens_kampe_kupon">ID: 2 - Bet: 2</div> <div class="kupon_gruppe">Group - 21:</div> <div class="dagens_kampe_kupon">ID: 1 - Bet: X</div> <div class="dagens_kampe_kupon">ID: 2 - Bet: 1</div> <div class="kupon_gruppe">Group - 22:</div> <div class="dagens_kampe_kupon">ID: 1 - Bet: X</div> <div class="dagens_kampe_kupon">ID: 2 - Bet: X</div>

preferences:
37.51 ms | 461 KiB | 5 Q