3v4l.org

run code in 300+ PHP versions simultaneously
<?php function hyphenate(array $numbers) { $result = []; $ref = null; foreach ($numbers as $i => $number) { if ($ref && $number == $numbers[$i - 1] + 1) { $ref = strtok($ref, "-") . "-$number"; } else { unset($ref); $ref = $number; $result[] =& $ref; } } return implode(',', $result); } var_export([ hyphenate(explode(' ', '')), hyphenate(explode(' ', '1')), hyphenate(explode(' ', '1 2')), hyphenate(explode(' ', '1 3')), hyphenate(explode(' ', '1 3 4 6')), hyphenate(explode(' ', '1 3 4 6 7')), hyphenate(explode(' ', '1 2 3 4 5')), hyphenate(explode(' ', '1 2 3 5 6 10 12 13')), ]);
Output for git.master_jit, git.master, rfc.property-hooks
array ( 0 => '', 1 => '1', 2 => '1-2', 3 => '1,3', 4 => '1,3-4,6', 5 => '1,3-4,6-7', 6 => '1-5', 7 => '1-3,5-6,10,12-13', )

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:
49.47 ms | 991 KiB | 4 Q