3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['id' => 1, 'nickname' => 'abc', 'game' => 'abc', 'checkbox' => 1], ['id' => 2, 'nickname' => 'xyz', 'game' => 'zyx', 'checkbox' => 0], ['id' => 5, 'nickname' => 'xyz', 'game' => 'abc', 'checkbox' => 1], ['id' => 6, 'nickname' => 'afg', 'game' => 'zyx', 'checkbox' => 1], ]; // The data must be sorted by the game, that's the key $sortedData = [ ['id' => 1, 'nickname' => 'abc', 'game' => 'abc', 'checkbox' => 1], ['id' => 5, 'nickname' => 'xyz', 'game' => 'abc', 'checkbox' => 1], ['id' => 2, 'nickname' => 'xyz', 'game' => 'zyx', 'checkbox' => 0], ['id' => 6, 'nickname' => 'afg', 'game' => 'zyx', 'checkbox' => 1], ]; // Figure out which game should span how many rows ahead of time foreach ($sortedData as $row) { $gameCounts[$row['game']] ??= 0; $gameCounts[$row['game']]++; } echo '<table border="1">'; echo '<thead>'; echo '<tr>'; foreach (array_keys($sortedData[0]) as $header) { echo '<th>'.$header.'</th>'; } echo '</tr>'; echo '</thead>'; echo '<tbody>'; $previousGame = null; foreach ($sortedData as $row) { echo '<tr>'; foreach ($row as $key => $value) { if ($key === 'game') { // Game changed - span the cell over the correct number of rows if ($previousGame !== $value) { echo '<td rowspan="'.$gameCounts[$value].'">'.$value.'</td>'; $previousGame = $value; } continue; } echo '<td>'.$value.'</td>'; } echo '</tr>'; } echo '</tbody>'; echo '</table>';
Output for git.master_jit, git.master
<table border="1"><thead><tr><th>id</th><th>nickname</th><th>game</th><th>checkbox</th></tr></thead><tbody><tr><td>1</td><td>abc</td><td rowspan="2">abc</td><td>1</td></tr><tr><td>5</td><td>xyz</td><td>1</td></tr><tr><td>2</td><td>xyz</td><td rowspan="2">zyx</td><td>0</td></tr><tr><td>6</td><td>afg</td><td>1</td></tr></tbody></table>

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
70.66 ms | 406 KiB | 5 Q