";
for ($col = 1; $col <= 3; $col++) { // 3 months per row
$month = ($row * 3) + $col;
$monthName = $monthNames[$month - 1];
echo "";
echo "$monthName";
echo "";
echo "";
foreach ($dayNames as $dayName) {
echo "$dayName | ";
}
echo " ";
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$startDay = date('w', mktime(0, 0, 0, $month, 1, $year));
echo "";
for ($i = 0; $i < $startDay; $i++) echo " | ";
for ($day = 1; $day <= $daysInMonth; $day++) {
$class = (($startDay + $day - 1) % 7 == 0) ? "sunday" : "";
echo "$day | ";
if (($startDay + $day) % 7 == 0) echo " ";
}
while (($startDay + $daysInMonth) % 7 != 0) {
echo " | ";
$startDay++;
}
echo " | ";
}
echo "
";
}
echo "