前几周的数组 [英] Array of previous weeks

查看:26
本文介绍了前几周的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个周数组,供用户选择每周查看统计数据.

I am trying to create an array of weeks for users to select to view stats week on week.

我正在寻找一个数组,它具有一周开始的时间戳(星期一 00.00 到星期日 11.59),然后我可以在 MYSQL 查询中使用它.

What I'm looking for is an array that has the timestamp of week start (monday 00.00 to sunday 11.59) that I can then use in MYSQL queries.

有没有人有可能有帮助的代码?我正在考虑做类似的事情:编辑,感谢以下答案:

Has anyone got an code that might assist? I was thinking of doing something like: EDIT, Thanks to the below answer:

' 公共函数 get_weeks() {$valid_dates = array();$date_counter = 0;
$date_counter = strtotime("下周四");//我喜欢做一个懒惰的混蛋!$i = 0;

' public function get_weeks () { $valid_dates = array(); $date_counter = 0;
$date_counter = strtotime("next thursday"); // I love being a lazy bastard! $i = 0;

    while ($i < 10) {
       array_push($valid_dates, $date_counter);
       $date_counter = strtotime("previous sunday 23:59:59", $date_counter); 
       $i++;
     }

    foreach ($valid_dates as $date) {
        $values[$date]['start'] = $date;
        $values[$date]['end']   = $date + 604800;
    }

    return $values;
}'

推荐答案

我昨天写了一个类似问题的解决方案 此处.这是 OP 问题的错误方法,但它为您的问题提供了正确的方向.由于时间限制,我现在无法修改它,但应该不会太难.

I wrote a solution for a similar question yesterday here. It was the wrong approach for the OP's question but it goes into the right direction for your question. I can't modify it right now due to time constraints, but it shouldn't be too hard to do.

提示:Strtotime 可以做类似的事情

Hint: Strtotime can do things like

$timestamp = strtotime("last monday 0:00"); 
strtotime("next sunday 23:59:59", $timestamp); 

这篇关于前几周的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆