3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ "prefix1 foo", "prefix2 bar", "prefix1 aaa", "prefix2 bbb", "prefix3 ccc", "prefix1 111", "prefix2 222" ]; $prefixes = ['prefix1', 'prefix2', 'prefix3']; $output = array(); $lastidx = count($prefixes); foreach ($input as $item) { list($prefix, $value) = explode(' ', $item); $index = array_search($prefix, $prefixes); if ($index < $lastidx) $output[] = array(); $output[count($output)-1][$prefix] = $value; $lastidx = $index; } print_r($output);
Output for git.master_jit, git.master, rfc.property-hooks
Array ( [0] => Array ( [prefix1] => foo [prefix2] => bar ) [1] => Array ( [prefix1] => aaa [prefix2] => bbb [prefix3] => ccc ) [2] => Array ( [prefix1] => 111 [prefix2] => 222 ) )

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