<?php
print_r(get_thirty_days((new \DateTime())->getTimestamp()));
function get_thirty_days(int $start_date_ts, int $days = null) {
$days = $days ?? 30;
$dates = [];
while ($days--) {
$dates[] = date('Y-m-d', $start_date_ts + ($days * (60 * 60 * 24)));
}
return $dates;
}
- Output for 8.4.1 - 8.4.13
- Deprecated: get_thirty_days(): Implicitly marking parameter $days as nullable is deprecated, the explicit nullable type must be used instead in /in/UXPA0 on line 5
Array
(
[0] => 2018-01-30
[1] => 2018-01-29
[2] => 2018-01-28
[3] => 2018-01-27
[4] => 2018-01-26
[5] => 2018-01-25
[6] => 2018-01-24
[7] => 2018-01-23
[8] => 2018-01-22
[9] => 2018-01-21
[10] => 2018-01-20
[11] => 2018-01-19
[12] => 2018-01-18
[13] => 2018-01-17
[14] => 2018-01-16
[15] => 2018-01-15
[16] => 2018-01-14
[17] => 2018-01-13
[18] => 2018-01-12
[19] => 2018-01-11
[20] => 2018-01-10
[21] => 2018-01-09
[22] => 2018-01-08
[23] => 2018-01-07
[24] => 2018-01-06
[25] => 2018-01-05
[26] => 2018-01-04
[27] => 2018-01-03
[28] => 2018-01-02
[29] => 2018-01-01
)
- Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.5, 7.4.7 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.25
- Array
(
[0] => 2018-01-30
[1] => 2018-01-29
[2] => 2018-01-28
[3] => 2018-01-27
[4] => 2018-01-26
[5] => 2018-01-25
[6] => 2018-01-24
[7] => 2018-01-23
[8] => 2018-01-22
[9] => 2018-01-21
[10] => 2018-01-20
[11] => 2018-01-19
[12] => 2018-01-18
[13] => 2018-01-17
[14] => 2018-01-16
[15] => 2018-01-15
[16] => 2018-01-14
[17] => 2018-01-13
[18] => 2018-01-12
[19] => 2018-01-11
[20] => 2018-01-10
[21] => 2018-01-09
[22] => 2018-01-08
[23] => 2018-01-07
[24] => 2018-01-06
[25] => 2018-01-05
[26] => 2018-01-04
[27] => 2018-01-03
[28] => 2018-01-02
[29] => 2018-01-01
)
- Output for 7.4.6
- Array
(
[0] => 2020-06-15
[1] => 2020-06-14
[2] => 2020-06-13
[3] => 2020-06-12
[4] => 2020-06-11
[5] => 2020-06-10
[6] => 2020-06-09
[7] => 2020-06-08
[8] => 2020-06-07
[9] => 2020-06-06
[10] => 2020-06-05
[11] => 2020-06-04
[12] => 2020-06-03
[13] => 2020-06-02
[14] => 2020-06-01
[15] => 2020-05-31
[16] => 2020-05-30
[17] => 2020-05-29
[18] => 2020-05-28
[19] => 2020-05-27
[20] => 2020-05-26
[21] => 2020-05-25
[22] => 2020-05-24
[23] => 2020-05-23
[24] => 2020-05-22
[25] => 2020-05-21
[26] => 2020-05-20
[27] => 2020-05-19
[28] => 2020-05-18
[29] => 2020-05-17
)
- Output for 5.6.0 - 5.6.40
- Parse error: syntax error, unexpected '?' in /in/UXPA0 on line 6
Process exited with code 255.
preferences:
153.6 ms | 411 KiB | 5 Q