您需要在给定的日,月和年中使用三个for循环和查找进行迭代。如果日期,月份和年份可用,则将它们放入变量中。
PHP代码如下
<!DOCTYPE html>
<html>
<body>
<?php
$givenDate = '2018-04-28';
$fiveYears = '2018,2019,2020,2021,2022';
$fiveMonths = '03,05,07,08,09';
$fiveDays = '25,26,27,28,29';
$fYears = explode(',', $fiveYears);
$fMonths = explode(',', $fiveMonths);
$fDays = explode(',', $fiveDays);
$nextDate = null;
foreach($fYears as $yr) {
foreach($fMonths as $mn) {
foreach($fDays as $dy) {
$t = $yr.'-'.$mn.'-'.$dy;
if($t > $givenDate) {
$nextDate = $t;
break 3;
}
}
}
}
if($nextDate) {
echo 'The next date value is =' . $nextDate;
}
else {
echo 'No date is found.';
}
?>
</body>
</html>输出结果
这将产生以下输出
The next date value is =2018-05-25