"Январь", 2 => "Февраль", 3 => "Март", 4 => "Апрель", 5 => "Май", 6 => "Июнь", 7 => "Июль", 8 => "Август", 9 => "Сентябрь", 10 => "Октябрь", 11 => "Ноябрь", 12 => "Декабрь"); function check($var) { return ($var != '.' && $var != '..'); } foreach (array_filter(scandir($dir), 'check') as $mon) foreach (array_filter(scandir($dir.'/'.$mon), 'check') as $photo) { $photo = explode('_', $photo); $all[$mon][$photo[0]][$photo[1]][] = $photo[2]; } foreach ($all as $mon => $var1) { echo ''; foreach ($var1 as $day => $var2) { $row = ''; $rowspan = 0; foreach ($var2 as $order => $var3) { if ($rowspan > 0) $row .= ''; $row .= ''; $rowspan++; } echo ' 1) echo ' rowspan="'.$rowspan.'"'; echo '>'.$day.''.$row; } echo '
'.$month[$mon].'
ДеньЗаказФото
'.$order.''; foreach ($var3 as $i => $link) $row .= ' ['.($i+1).']'; $row .= '

'; } ?>

NB! [1] - первым всегда чек