3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [['color'=>'#000000','size'=>'L','count'=>2], ['color'=>'#000000','size'=>'XL','count'=>1], ['color'=>'#ffffff','size'=>'L','count'=>2], ['color'=>'#ffffff','size'=>'XL','count'=>1], ['color'=>'#ff0000','size'=>'L','count'=>1]]; $colors = []; foreach ($input as $product) { extract($product); $colors[$color][$size] = $count; } print_r($colors); $output = []; foreach ($colors as $color => $sizes) { $data = []; foreach ($sizes as $size => $count) { $data[] = ['value' => $size, 'count' => $count]; } $output[] = ['color' => $color, 'size' => $data]; } echo json_encode($output, JSON_PRETTY_PRINT);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [#000000] => Array ( [L] => 2 [XL] => 1 ) [#ffffff] => Array ( [L] => 2 [XL] => 1 ) [#ff0000] => Array ( [L] => 1 ) ) [ { "color": "#000000", "size": [ { "value": "L", "count": 2 }, { "value": "XL", "count": 1 } ] }, { "color": "#ffffff", "size": [ { "value": "L", "count": 2 }, { "value": "XL", "count": 1 } ] }, { "color": "#ff0000", "size": [ { "value": "L", "count": 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:
25.56 ms | 408 KiB | 5 Q