3v4l.org

run code in 300+ PHP versions simultaneously
<?php $yaml = [ 'components' => [ [ 'cachet' => [ 'componentgroup' => 'FOO', 'componentname' => 'BAR' ] ], [ 'cachet' => [ 'componentgroup' => 'Key1', 'componentname' => 'Value1' ] ], [ 'cachet' => [ 'componentgroup' => 'Key2', 'componentname' => 'Value2' ] ], [ 'cachet' => [ 'componentgroup' => 'FOO', 'componentname' => 'BAZ' ] ], [ 'cachet' => [ 'componentgroup' => 'Key3', 'componentname' => 'Value3' ] ] ] ]; $yamlMap = []; foreach ($yaml['components'] as $yamlComponent) { $key = $yamlComponent['cachet']['componentgroup']; $value = $yamlComponent['cachet']['componentname']; if (isset($yamlMap[$key])) { if (is_array($yamlMap[$key])) { $yamlMap[$key][] = $value; } else { $yamlMap[$key] = [$yamlMap[$key], $value]; } } else { $yamlMap[$key] = $value; } } var_export($yamlMap);
Output for git.master_jit, git.master, rfc.property-hooks
array ( 'FOO' => array ( 0 => 'BAR', 1 => 'BAZ', ), 'Key1' => 'Value1', 'Key2' => 'Value2', 'Key3' => 'Value3', )

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:
153.05 ms | 405 KiB | 5 Q