3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fruits = [ ['name_id' => 'apple2', 'color' => 'green', 'taste' => 'sweet', 'quantity' => '2', 'price' => 'priceless'], ['name_id' => 'apple1', 'color' => 'red', 'taste' => 'sweet', 'quantity' => '3', 'price' => 'cheap'], ['name_id' => 'apple3', 'color' => 'red', 'taste' => 'sweet', 'quantity' => '1', 'price' => '2'], ['name_id' => 'apple4', 'color' => 'blue', 'taste' => 'another', 'quantity' => '2', 'price' => '1'], ['name_id' => 'apple5', 'color' => 'red', 'taste' => 'bitter', 'quantity' => '1', 'price' => '100'], ['name_id' => 'apple6', 'color' => 'red', 'taste' => 'indefinable', 'quantity' => '6', 'price' => '100'], ['name_id' => 'apple7', 'color' => 'red', 'taste' => 'indefinable', 'quantity' => '2', 'price' => '10'], ['name_id' => 'apple8', 'color' => 'green', 'taste' => 'sour', 'quantity' => '2', 'price' => 'priceless'], ['name_id' => 'apple9', 'color' => 'green', 'taste' => 'sour', 'quantity' => '1', 'price' => 'cheap'] ]; $param1 = 'color'; $param2 = 'taste'; $result = []; foreach ($fruits as $fruit) { $defaults[$fruit[$param2]] = ''; $result[$fruit[$param1]][$fruit[$param2]] = ($result[$fruit[$param1]][$fruit[$param2]] ?? 0) + $fruit['quantity']; } ksort($defaults); ksort($result); echo "<table border=1 cellspacing=0 cellpadding=4>"; echo '<tr><th></th><th>' . implode('</th><th>', array_keys($defaults)) . "</th></tr>\n"; foreach ($result as $p1 => $row) { $row = array_replace(['label' => $p1] + $defaults, $row); echo '<tr><td>' . implode('</td><td>', $row) . "</td></tr>\n"; } echo "</table>";
Output for git.master, git.master_jit, rfc.property-hooks
<table border=1 cellspacing=0 cellpadding=4><tr><th></th><th>another</th><th>bitter</th><th>indefinable</th><th>sour</th><th>sweet</th></tr> <tr><td>blue</td><td>2</td><td></td><td></td><td></td><td></td></tr> <tr><td>green</td><td></td><td></td><td></td><td>3</td><td>2</td></tr> <tr><td>red</td><td></td><td>1</td><td>8</td><td></td><td>4</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:
859.25 ms | 406 KiB | 5 Q