Project

General

Profile

Feature #14472 ยป 0000646-expandList.php

Administrator Admin, 2005-03-03 13:39

 
<?php

function expandList($list) {
$items = explode(',',$list);
$list = array();
while(list(,$item)=each($items)) {
$range = explode('-',$item);
if (isset($range[1])) {
for ($n=$range[0]; $n<=$range[1]; $n++)
$list[] = $n;
} else {
$list[] = $item;
}
}

return implode(',',$list);
}

echo expandList('1,2,3'),"\n";
echo expandList('1,2-3,4'),"\n";
echo expandList('1,2-6,10-12'),"\n";

?>
    (1-1/1)