I'd like to make an array starts with the first day-o-month and finishes at the last.
$days = array();
$sdays = cal_days_in_month(CAL_GREGORIAN, date('m'), date('Y'));
$d = new DateTime();
$d->modify('first day of this month');
for($i; $i<$sdays; $i++)
{
$days[(int)$d->format('W')][(int)$d->format('N')] = $d->format('Y-m-d');
$d->add(new DateInterval('P1D'));
}
print_r($days);
exit();
So it's pretty simple. But the result is looks like the DateInterval function don't work as it should.
Expectation:
Array
(
[14] => Array // week
(
[1] => 2013-04-01
[2] => 2013-04-02
[3] => 2013-04-03
...
Reality:
Array
(
[14] => Array
(
[1] => 2013-04-01
)
)
Aye, the method, how you can fix this also simple, create an another DateTime object, modify to the first day, then create a new DateTime object from the first day, then you can add DateInterval to it.
So after i modified my DateTime object by $d->modify no date can added to it. But the question is why? I'd like to understand this.
Thanks for the answer.
Répás