![](/img/trans.png)
[英]PHP: Get next days of the week depending on current week day then display in chart label
[英]PHP get next days of the week depending on current day of the week
我必须用访客人数填写图表,但是在显示当前周数据时,我将第二天的值设为0。
EG:今天是星期一,所以我将2016-06-20作为列值,但下一个列值名称为0,因为我接下来的几天没有数据。
图表索引必须是这样的:
|| 20 Jun 2016 || 21 Jun 2016 || 22 Jun 2016 || 23 Jun 2016 || etc.
现在我得到了:
|| 20 Jun 2016 || 1 Jan 1970 || 1 Jan 1970 || 1 Jan 1970 || etc.
因此,我尝试使用此功能填充缺少的日子:
function get_day($count) {
if ($count == NULL) {
$dweek = date("w");
for ($i = 1; $i <= 6; $i++) {
echo $i;
switch ($i) {
case 1:
$day = $dweek+1;
break;
case 2:
$day = $dweek+2;
break;
case 3:
$day = $dweek+3;
break;
case 4:
$day = $dweek+4;
break;
case 5:
$day = $dweek+5;
break;
case 6:
$day = $dweek+6;
break;
}
}
$current = date("d M Y",strtotime("+$day day"));
} else {
$current = date("d M Y",strtotime($count));
}
return $current;
}
但是现在使用它我得到:
|| 20 Jun 2016 || 27 Jun 2016 || 27 Jun 2016 || 27 Jun 2016 || etc.
所以我想念一些东西,但是两个小时后我看不到该怎么办。
感谢您的帮助。
$res = "|| ";
for ($d = 1; $d < 8; $d++) {
$dt = new DateTime();
$m = $dt->modify("+$d days");
$f = $m->format("d M Y");
$res .= $f . " || ";
}
echo $res;
$date = '2016-06-20'; //replace this by your date
$statement = '';
for($i = 0; $i < 7; $i++){
$statement.= ' || ' . date('d M y', strtotime("$date +$i day"));
}
echo $statement;
现在,您可以使用日期而不是$ date。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.