3v4l.org

run code in 300+ PHP versions simultaneously
<?php $ids = [1, 1, 1, 2, 5, 1]; $sizes = ["m", "m", "m", "s", "xl", "s"]; $colors = ["red", "red", "yellow", "orange", "red", "orange"]; foreach ($ids as $i => $id) { $size = $sizes[$i]; $color = $colors[$i]; $tempKey = "{$id}:{$size}:{$color}"; if (!isset($result[$tempKey])) { $result[$tempKey] = [ 'id' => $id, 'size' => $size, 'color' => $color, 'stock' => 1 ]; } else { ++$result[$tempKey]['stock']; } } var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'id' => 1, 'size' => 'm', 'color' => 'red', 'stock' => 2, ), 1 => array ( 'id' => 1, 'size' => 'm', 'color' => 'yellow', 'stock' => 1, ), 2 => array ( 'id' => 2, 'size' => 's', 'color' => 'orange', 'stock' => 1, ), 3 => array ( 'id' => 5, 'size' => 'xl', 'color' => 'red', 'stock' => 1, ), 4 => array ( 'id' => 1, 'size' => 's', 'color' => 'orange', 'stock' => 1, ), )

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:
65.42 ms | 402 KiB | 8 Q