Php 在整个月内循环一个月中的几天
我正在构建多日历,我有一个水平界面: 我正在尝试运行一周中的几天Php 在整个月内循环一个月中的几天,php,loops,for-loop,Php,Loops,For Loop,我正在构建多日历,我有一个水平界面: 我正在尝试运行一周中的几天S、M、T、W、T、F、S 整个月,而不仅仅是图中的前7个月 绘制日历的函数: //our case "SUN" if(AC_START_DAY=="sun"){ for($k=0; $k<7; $k++){ $weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8'); $list_day_titles.='<li class="
S、M、T、W、T、F、S
整个月,而不仅仅是图中的前7个月
绘制日历的函数:
//our case "SUN"
if(AC_START_DAY=="sun"){
for($k=0; $k<7; $k++){
$weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
$list_day_titles.='<li class="cal_weekday"> '.$weekday.'</li>';
}
}
//If we chose Monday as start week.
else{
if ($first_week_day == 0) $first_week_day =7;
for($k=1; $k<=7; $k++){
if($k==7) $weekday = mb_substr($lang["day_0"][0],0,1,'UTF-8');
else $weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
$list_day_titles.='<li title="'.$lang["day_".$k.""].'"> '.$weekday.'</li>';
}
}
已经定义
$month=sprintf("%02s",$month);
// define vars
$today_timestamp = mktime(0,0,0,date('m'),date('d'),date('Y')); # current timestamp - used to check if date is in past
$this_month = getDate(mktime(0, 0, 0, $month, 1, $year)); # convert month to timestamp
$first_week_day = $this_month["wday"]; # define first weekday (0-6)
$days_in_this_month = cal_days_in_month(CAL_GREGORIAN,$month,$year); # define number of days in week
$day_counter_tot = 0; # count total number of days showin INCLUDING previous and next months - use to get 6th row of dates
看起来,$lang[“day”.$k.“”]
只是在计算从0到6的天数。。我怎样才能在月底前完成is循环
注意:我尝试将
$k使用循环增加到30/31天
然后换这条线
$weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
到
这将为您提供每个星期天的0天
0 % 7 = 0 (sunday)
1 % 7 = 1 (monday)
...
7 % 7 = 0 (sunday again)
8 % 7 = 1 (monday again)
使用循环到30/31天
然后换这条线
$weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
到
这将为您提供每个星期天的0天
0 % 7 = 0 (sunday)
1 % 7 = 1 (monday)
...
7 % 7 = 0 (sunday again)
8 % 7 = 1 (monday again)
您可以使用此代码生成当月的所有日期
for ($date = strtotime(date('Y-m-01')); $date < strtotime(date('Y-m-t')); $date = strtotime("+1 day", $date)) {
echo date("l-d", $date)."<br>";
}
您可以使用此代码生成当前月份的所有日期
for ($date = strtotime(date('Y-m-01')); $date < strtotime(date('Y-m-t')); $date = strtotime("+1 day", $date)) {
echo date("l-d", $date)."<br>";
}
看起来你几乎做对了。
您只需要稍微修改代码,使其按您希望的方式工作。
您只需将代码更改为:
$number_of_days_in_the_future = 42; // Here you can put in the number of days for which you want to display the corresponding letter, and based on your screenshot that is 42
//our case "SUN"
if(AC_START_DAY=="sun"){
for($i=0; $i<$number_of_days_in_the_future; $i++){
$k = $i % 7;
$weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
$list_day_titles.='<li class="cal_weekday"> '.$weekday.'</li>';
}
}
//If we chose Monday as start week.
else{
if ($first_week_day == 0) $first_week_day =7;
for($i=1; $i<=$number_of_days_in_the_future; $i++){
$k = $i % 7;
if($k==7) $weekday = mb_substr($lang["day_0"][0],0,1,'UTF-8');
else $weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
$list_day_titles.='<li title="'.$lang["day_".$k.""].'"> '.$weekday.'</li>';
}
}
$number\u未来的天数=42;//在这里,您可以输入您希望显示相应字母的天数,并基于42的屏幕截图
//我们的案例“太阳”
如果(AC_开始日==“太阳”){
因为($i=0;$i看起来你几乎做对了。
您只需要稍微修改代码,使其按您希望的方式工作。
您只需将代码更改为:
$number_of_days_in_the_future = 42; // Here you can put in the number of days for which you want to display the corresponding letter, and based on your screenshot that is 42
//our case "SUN"
if(AC_START_DAY=="sun"){
for($i=0; $i<$number_of_days_in_the_future; $i++){
$k = $i % 7;
$weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
$list_day_titles.='<li class="cal_weekday"> '.$weekday.'</li>';
}
}
//If we chose Monday as start week.
else{
if ($first_week_day == 0) $first_week_day =7;
for($i=1; $i<=$number_of_days_in_the_future; $i++){
$k = $i % 7;
if($k==7) $weekday = mb_substr($lang["day_0"][0],0,1,'UTF-8');
else $weekday = mb_substr($lang["day_".$k.""],0,1,'UTF-8');
$list_day_titles.='<li title="'.$lang["day_".$k.""].'"> '.$weekday.'</li>';
}
}
$number_of_days_in_the_future=42;//在这里,您可以根据42的屏幕截图输入要显示相应字母的天数
//我们的案例“太阳”
如果(AC_开始日==“太阳”){
对于($i=0;$i开始使用这些函数时,需要知道它们处理的月份,以便它可以计算一个月内的五月天数,因此您可以将循环限制更改为正确的输出天数。开始使用这些函数时,需要知道它们处理的月份,以便它可以计算一个月内可能有几天,因此您可以将循环限制更改为正确的输出天数