<?php
$begin = new DateTime('2020-12-01');
$end = new DateTime('2021-01-01');
$row = array('monday' => 1, 'tuesday' => 0, 'wednesday' => 1, 'thursday' => 1, 'friday' => 1, 'saturday' => 0, 'sunday' => 1);
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($begin, $interval ,$end);
$array = array();
foreach($daterange as $date){
if ($row[strtolower($date->format('l'))]) {
$array[] = $date->format("D Y-m-d");
}
}
print_r($array);
- Output for 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.30, 8.2.0 - 8.2.25, 8.3.0 - 8.3.13
- Array
(
[0] => Wed 2020-12-02
[1] => Thu 2020-12-03
[2] => Fri 2020-12-04
[3] => Sun 2020-12-06
[4] => Mon 2020-12-07
[5] => Wed 2020-12-09
[6] => Thu 2020-12-10
[7] => Fri 2020-12-11
[8] => Sun 2020-12-13
[9] => Mon 2020-12-14
[10] => Wed 2020-12-16
[11] => Thu 2020-12-17
[12] => Fri 2020-12-18
[13] => Sun 2020-12-20
[14] => Mon 2020-12-21
[15] => Wed 2020-12-23
[16] => Thu 2020-12-24
[17] => Fri 2020-12-25
[18] => Sun 2020-12-27
[19] => Mon 2020-12-28
[20] => Wed 2020-12-30
[21] => Thu 2020-12-31
)
preferences:
92.34 ms | 408 KiB | 5 Q