Get the dates of the current php week

You need to print the dates of the current week

 <?php for($i = 1;$i < 7;$i++) { ?>
   <div class="<?php echo date("Y-m-d", strtotime("+".$i." day")); ?>"></div>   
 <?php } ?>

This is how it works, but of course it doesn't display the current date...

Author: Денис Линник, 2020-04-30

2 answers

<?php
$date = strtotime('monday this week');
for($i = 1;$i < 7;$i++) {?>
   <div class="<?php echo date("Y-m-d", $date); ?>"></div> 
<?php 
   $date =  strtotime('+1 day', $date);
} ?>
 1
Author: splash58, 2020-04-30 17:53:18

Get the current date, the current day of the week. We know the difference in days between today's day of the week and Monday (Monday-0, Tuesday-1, Wednesday-2, etc.). Knowing this, you can easily determine the date of Monday (we subtract the required number of days from the current date). We add 6 days to Monday - we get Sunday.

 0
Author: nightflash, 2020-04-30 12:57:50