我正在为一个小型预订系统设计一个小型 PHP 日历。最后一个功能是阻止一些不可用的日期,我已将其存储在 PHP 数组中。实现这一目标的最佳方法是什么?请我需要一些关于如何做到这一点的建议。谢谢
// Set your timezone!!
date_default_timezone_set('Europe/Madrid');
// Get prev & next month
if (isset($_GET['ym'])) {
$ym = $_GET['ym'];
} else {
// This month
$ym = date('Y-m');
}
// Check format
$timestamp = strtotime($ym . '-01'); // the first day of the month
if ($timestamp === false) {
$ym = date('Y-m');
$timestamp = strtotime($ym . '-01');
}
// Today (Format:2018-08-8)
$today = date('Y-m-j');
// Title (Format:August, 2018)
$title = date('F, Y', $timestamp);
// Create prev & next month link
$prev = date('Y-m', strtotime('-1 month', $timestamp));
$next = date('Y-m', strtotime('+1 month', $timestamp));
// Number of days in the month
$day_count = date('t', $timestamp);
// 1:Mon 2:Tue 3: Wed ... 7:Sun
$str = date('N', $timestamp);
// Array for calendar
$weeks = [];
$week = '';
// Add empty cell(s)
$week .= str_repeat('<td></td>', $str - 1);
for ($day = 1; $day <= $day_count; $day++, $str++) {
$date = $ym . '-' . $day;
if ($today == $date) {
$week .= '<td class="today">';
} else {
$week .= '<td>';
}
$week .= $day . '</td>';
// Sunday OR last day of the month
if ($str % 7 == 0 || $day == $day_count) {
// last day of the month
if ($day == $day_count && $str % 7 != 0) {
// Add empty cell(s)
$week .= str_repeat('<td></td>', 7 - $str % 7);
}
$weeks[] = '<tr>' . $week . '</tr>';
$week = '';
}
}
如果我在 php 中有一个数组,其日期格式为“2020-08-12”,该数组必须不可用或不可选择,我该怎么办。
BIG阳