<?php
$a = array('2007-12-14',
'2007-12-16',
'2007-12-17',
'2007-12-22',
'2007-12-23',
'2007-12-26',
'2007-12-28',
'2008-01-02',
'2008-01-06',
'2008-01-08',
'2008-01-12',
'2008-01-14',
'2008-02-17',
'2008-02-19',
'2008-02-20');
foreach ($a as $date){
list($y,$m,$d) = explode('-',$date);
$ad[$y][$m][] = $d;
}
foreach ($ad as $y => $mounts){
foreach ($mounts as $m => $days){
for ($i = 0; $i < count($days)-1; $i++){
if (abs($days[$i]) + 1 == $days[$i + 1]) $days[$i + 1] *= -1;
if ($days[$i] < 0 and $days[$i+1]<0) unset($days[$i]);
}
$out .= date("F", mktime(0, 0, 0, $m, 1, 2000));
$out1 ='';
foreach ($days as $d) $out1 .= ($d>0 ? ', ':'').$d;
$out .= substr($out1,1).' ';
}
$out .= "$y ";
}
echo $out;
?>