修改PHP数组中的日期

I'm able to fill an array with the date of every Monday for the next 4 weeks. The problem is when 12am Monday hits, it immediately shifts the dates forward one week. I don't want it to do that until the the end of Monday, like on Tuesday at 12am. Any thoughts?

$start = strtotime( "next monday" );
$end = strtotime( "+4 weeks", $start );

while ( $start < $end ) {

    $dates[] = date( "D, M d", $start );
    $start = strtotime( "+1 week", $start );

}

Maybe I can leave the array and just change it when I echo them? This is what I'm doing now.

<h3><?php echo $dates[0]; ?></h3>
   <p></p>

<h3><?php echo $dates[1]; ?></h3>
   <p></p>

and so on

I figured it out. I just added an if statement before the while. If the current day is a Monday it just moves the start date a week into the "past" to make it equal to today's date. Here's the whole thing:

$start == strtotime( 'next monday' );

if( date('N') == 1 ) {
    $start = strtotime( '-1 week', $start );
}

$end = strtotime( '+4 weeks', $start );

while ( $start < $end ) {
    $dates[] = date( 'D, M d', $start );
    $start = strtotime( '+1 week', $start );
}

When I have to deal with date calculation I use Carbon. It is a good choice! https://github.com/briannesbitt/Carbon

You can set a start date and start calculating. Cool!

Hope it helps!

Step 1 day back from today

$start = strtotime( "-1 day" );
$start = strtotime( "next monday", $start );

The problem, as you noted, is strtotime("next monday") returns this week's Monday on Sunday but next Monday after Sunday.

It seems you always want this week's Monday. As such, you can use the relative time string monday this week:

$start = strtotime('monday this week');