3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function parse_range_str($str_input) { $arr_result = []; foreach (preg_split('/\s*,\s*/', $str_input) as $str_range) { $arr_range = preg_split('/\s*-\s*/', $str_range); if (isset($arr_range[1])) { $arr_result = array_merge($arr_result, range((int) $arr_range[0], (int) $arr_range[1])); } else { $arr_result[] = (int) $arr_range[0]; } } return $arr_result; } var_dump(parse_range_str('1,2,8-12,16'));
Output for 5.4.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
array(8) { [0]=> int(1) [1]=> int(2) [2]=> int(8) [3]=> int(9) [4]=> int(10) [5]=> int(11) [6]=> int(12) [7]=> int(16) }
Output for hhvm-3.10.0

Process exited with code 153.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/LCMWl on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/LCMWl on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/LCMWl on line 5
Process exited with code 255.