3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $log = array ( array('Red', 'Steel'), array('Red', 'Wood'), array('Blue', 'Wood') ); $materials = array(); $colors = array(); foreach($log as $line) { $colors[$line[0]] = (!isset($colors[$line[0]])) ? 1 : $colors[$line[0]] + 1; $materials[$line[1]] = (!isset($materials[$line[1]])) ? 1 : $materials[$line[1]] + 1; } ?> <h2>Colors</h2>\n <?php foreach ($colors as $color => $amount) echo "{$color} => {$amount}<br>\n"; ?> <h2>Materials</h2>\n <?php foreach ($materials as $material => $amount) echo "{$material} => {$amount}<br>\n"; ?>
based on DQI2K
Output for 4.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
<h2>Colors</h2>\n Red => 2<br> Blue => 1<br> <h2>Materials</h2>\n Steel => 1<br> Wood => 2<br>