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 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.4, 8.3.6 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
<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>
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 <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>
Output for 5.6.12
Parse error: syntax error, unexpected '?' in /in/gpuqD on line 21
Process exited with code 255.

preferences:
188.74 ms | 410 KiB | 5 Q