PHP 最大连续签到天数

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$continue_days = 1;
$continue_days_array = [];
for ($i = 0; $i < $list_length; $i++) {
// 今天
$today = strtotime(explode(' ', $tracks[$i]->created_at)[0]);
//
if ($i == $list_length - 1) {
$continue_days_array[] = $continue_days;
} else {
$yesterday = strtotime(explode(' ', $tracks[$i + 1]->created_at)[0]);
$one_day = 24 * 3600;
if ($today - $yesterday == $one_day) {
$continue_days += 1;
} else {
$continue_days_array[] = $continue_days;
$continue_days = 1;
}
}
}
if (count($continue_days_array) > 0) {
$max_days = max($continue_days_array);
} else {
$max_days = 0;
}

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!