<?php
function my_calendar($month,$year) {
// Cria uma matriz contendo abreviações de dias da semana.
$daysOfWeek = array('Domingo','Segunda-feira','Terça-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sábado');
// Qual é o primeiro dia do mês em questão?
$firstDayOfMonth = mktime(0,0,0,$month, 1, $year);
// Quantos dias este mês contém?
$numberDays = date('t', $firstDayOfMonth);
// Recupere algumas informações sobre o primeiro dia do mês em questão.
$dateComponents = getdate($firstDayOfMonth);
// Qual é o valor do índice (0-6) do primeiro dia do mês em questão.
$dayOfWeek = $dateComponents['wday'];
//cabeçalho
$calendar[] = $year;
// foreach($daysOfWeek as $k => $week) {
// array_push($calendar, $week);
//}
// Cria os cabeçalhos do calendário
/* Cria o resto do calendário
Inicia o contador de dias, começando com o 1º. */
$currentDay = 1;
/* A variável $dayOfWeek é usada para
garantir que o calendário
display consiste em exatamente 7 colunas. */
if ($dayOfWeek > 0) {
$calendar[] = array('week' => $dayOfWeek); }
$month = str_pad($month, 2, "0", STR_PAD_LEFT
);
while ($currentDay <= $numberDays) {
//Sétima coluna (sábado) alcançada. Comece uma nova linha.
if ($dayOfWeek == 7) {
$dayOfWeek = 0;
}
$currentDayRel = str_pad($currentDay, 2, "0", STR_PAD_LEFT
);
$date = array('ano' => $year, 'mes' => $month , 'dia' => $currentDayRel);
$calendar[]= array('semana' => $daysOfWeek[$dayOfWeek],'data_eng' => "$year-$month-$currentDayRel", 'data'=> $date, 'dia_corrente_num' => $currentDay);
//Incremento
$currentDay++;
$dayOfWeek++;
}
// Preencha a linha da última semana do mês, se necessário
if ($dayOfWeek != 7) {
$remainingDays = 7 - $dayOfWeek;
$calendar[] = array('remainingDays' => $remainingDays);
}
return $calendar;
}
$month = $dateComponents['mon'];
$year = $dateComponents['year'];
$result1 = my_calendar($month, $year);
$result2= my_calendar(2, 2019);
'current_month' => $result1, //meses correntes
'set_month' => $result2 // um mes e ano setado...
);
PD9waHAKJGNhbGVuZGFyID0gYXJyYXkoKTsKZnVuY3Rpb24g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