Skip to content

Instantly share code, notes, and snippets.

@hasibkamal
Created November 13, 2016 19:12
Show Gist options
  • Save hasibkamal/1edd7d0fbd596fe163817ee7eb35067a to your computer and use it in GitHub Desktop.
Save hasibkamal/1edd7d0fbd596fe163817ee7eb35067a to your computer and use it in GitHub Desktop.
<?php
function serial($str){
$arr = explode(',', $str);
$series = array();
foreach($arr as $val){
if(strpos($val,'-')){
$_arr = explode('-', $val);
$series = array_merge($series,range($_arr[0], $_arr[1]));
}else{
array_push($series,$val);
}
}
return $series;
}
print_r(serial("1,2,3,4-6,7-15"));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment