You can use DatePeriod :
$firstMondayThisWeek= new DateTime('2011/06/01');
$firstMondayThisWeek->modify('tomorrow');
$firstMondayThisWeek->modify('last Monday');
$nextFiveWeekDays = new DatePeriod(
$firstMondayThisWeek,
DateInterval::createFromDateString('+1 weekdays'),
4
);
print_r(iterator_to_array($nextFiveWeekDays));
Note that it DatePeriodis Iterator, therefore, if you are not really fixed in the dates in the array, you can just go with the container DatePeriod.
The above will give something like ( demo )
Array
(
[0] => DateTime Object
(
[date] => 2011-05-30 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[1] => DateTime Object
(
[date] => 2011-05-31 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[2] => DateTime Object
(
[date] => 2011-06-01 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[3] => DateTime Object
(
[date] => 2011-06-02 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
[4] => DateTime Object
(
[date] => 2011-06-03 00:00:00
[timezone_type] => 3
[timezone] => Europe/Berlin
)
)
5.3
$firstMondayInWeek = strtotime('last Monday', strtotime('2011/06/01 +1 day'));
$nextFiveWeekDays = array();
for ($days = 1; $days <= 5; $days++) {
$nextFiveWeekDays[] = new DateTime(
date('Y-m-d', strtotime("+$days weekdays", $firstMondayInWeek))
);
}
, DateTime , API . , , DateTime .