3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ ['id' => 111, 'text' => 'yellow'], ['id' => 111, 'text' => 'red'], ['id' => 112, 'text' => 'green'], ]; $result = array_map(function($item) {return [ 'id' => $item['id'], 'text' => implode(', ', $item['colors']), ];}, array_reduce($data, function($reduced, $item){ if (!isset($reduced[$item['id']])) $reduced[$item['id']] = $item; $reduced[$item['id']]['colors'][] = $item['text']; return $reduced; }, [])); var_dump($result);
Output for git.master, git.master_jit, rfc.property-hooks
array(2) { [111]=> array(2) { ["id"]=> int(111) ["text"]=> string(11) "yellow, red" } [112]=> array(2) { ["id"]=> int(112) ["text"]=> string(5) "green" } }

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:
32.4 ms | 401 KiB | 8 Q