3v4l.org

run code in 300+ PHP versions simultaneously
<?php $resultObject = [ ['name' => 'Tom', 'value' => 15, 'year' => 2018], ['name' => 'Tom', 'value' => 4, 'year' => 2019], ['name' => 'Tom', 'value' => 6, 'year' => 2020], ['name' => 'Kate', 'value' => 18, 'year' => 2018], ['name' => 'Kate', 'value' => 20, 'year' => 2019], ]; $grouped = []; $columns = []; foreach ($resultObject as $row) { $grouped[$row['name']][$row['year']] = $row['value']; $columns[$row['year']] = $row['year']; } sort($columns); $defaults = array_fill_keys($columns, '-'); array_unshift($columns, 'name'); echo "<table>\n"; printf( "<tr><th>%s</th></tr>\n", implode('</th><th>', $columns) ); foreach ($grouped as $name => $records) { printf( "<tr><td>%s</td><td>%s</td></tr>\n", $name, implode('</td><td>', array_replace($defaults, $records)) ); } echo "</table>";
Output for git.master, git.master_jit, rfc.property-hooks
<table> <tr><th>name</th><th>2018</th><th>2019</th><th>2020</th></tr> <tr><td>Tom</td><td>15</td><td>4</td><td>6</td></tr> <tr><td>Kate</td><td>18</td><td>20</td><td>-</td></tr> </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:
30.14 ms | 406 KiB | 5 Q