3v4l.org

run code in 300+ PHP versions simultaneously
<?php function group_nums($array) { $ret = array(); $temp = array(); foreach($array as $val) { if(next($array) == ($val + 1)) $temp[] = $val; else if(count($temp) > 0) { $temp[] = $val; $ret[] = $temp[0].'-'.end($temp); $temp = array(); } else $ret[] = $val; } return $ret; } $a = [2,3,4,7,8,9,10,11,13,15]; print_r(group_nums($a));
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [0] => 2-4 [1] => 7-11 [2] => 13 [3] => 15 )

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