3v4l.org

run code in 300+ PHP versions simultaneously
<?php $year = date_create('today')->format('Y'); //remove comment next line for test's //$year = 2001; $dtStart = date_create('2 jan '.$year)->modify('last Monday'); $dtEnd = date_create('last monday of Dec '.$year); for($weeks = [];$dtStart <= $dtEnd;$dtStart->modify('+1 week')){ $key = $dtStart->format('W-Y'); $from = $dtStart->format('d/m/Y'); $to = (clone $dtStart)->modify('+6 Days')->format('d/m/Y'); $weeks[$key] = $from.' - '.$to; } var_export($weeks);

Abusive script

This script was stopped while abusing our resources

Output for 7.4.0 - 7.4.3, 7.4.5 - 7.4.33, 8.0.1 - 8.0.14, 8.0.16 - 8.0.21, 8.0.23 - 8.0.30, 8.1.0 - 8.1.1, 8.1.3 - 8.1.29, 8.2.0 - 8.2.23, 8.3.0 - 8.3.11
array ( '52-2022' => '26/12/2022 - 01/01/2023', '01-2023' => '02/01/2023 - 08/01/2023', '02-2023' => '09/01/2023 - 15/01/2023', '03-2023' => '16/01/2023 - 22/01/2023', '04-2023' => '23/01/2023 - 29/01/2023', '05-2023' => '30/01/2023 - 05/02/2023', '06-2023' => '06/02/2023 - 12/02/2023', '07-2023' => '13/02/2023 - 19/02/2023', '08-2023' => '20/02/2023 - 26/02/2023', '09-2023' => '27/02/2023 - 05/03/2023', '10-2023' => '06/03/2023 - 12/03/2023', '11-2023' => '13/03/2023 - 19/03/2023', '12-2023' => '20/03/2023 - 26/03/2023', '13-2023' => '27/03/2023 - 02/04/2023', '14-2023' => '03/04/2023 - 09/04/2023', '15-2023' => '10/04/2023 - 16/04/2023', '16-2023' => '17/04/2023 - 23/04/2023', '17-2023' => '24/04/2023 - 30/04/2023', '18-2023' => '01/05/2023 - 07/05/2023', '19-2023' => '08/05/2023 - 14/05/2023', '20-2023' => '15/05/2023 - 21/05/2023', '21-2023' => '22/05/2023 - 28/05/2023', '22-2023' => '29/05/2023 - 04/06/2023', '23-2023' => '05/06/2023 - 11/06/2023', '24-2023' => '12/06/2023 - 18/06/2023', '25-2023' => '19/06/2023 - 25/06/2023', '26-2023' => '26/06/2023 - 02/07/2023', '27-2023' => '03/07/2023 - 09/07/2023', '28-2023' => '10/07/2023 - 16/07/2023', '29-2023' => '17/07/2023 - 23/07/2023', '30-2023' => '24/07/2023 - 30/07/2023', '31-2023' => '31/07/2023 - 06/08/2023', '32-2023' => '07/08/2023 - 13/08/2023', '33-2023' => '14/08/2023 - 20/08/2023', '34-2023' => '21/08/2023 - 27/08/2023', '35-2023' => '28/08/2023 - 03/09/2023', '36-2023' => '04/09/2023 - 10/09/2023', '37-2023' => '11/09/2023 - 17/09/2023', '38-2023' => '18/09/2023 - 24/09/2023', '39-2023' => '25/09/2023 - 01/10/2023', '40-2023' => '02/10/2023 - 08/10/2023', '41-2023' => '09/10/2023 - 15/10/2023', '42-2023' => '16/10/2023 - 22/10/2023', '43-2023' => '23/10/2023 - 29/10/2023', '44-2023' => '30/10/2023 - 05/11/2023', '45-2023' => '06/11/2023 - 12/11/2023', '46-2023' => '13/11/2023 - 19/11/2023', '47-2023' => '20/11/2023 - 26/11/2023', '48-2023' => '27/11/2023 - 03/12/2023', '49-2023' => '04/12/2023 - 10/12/2023', '50-2023' => '11/12/2023 - 17/12/2023', '51-2023' => '18/12/2023 - 24/12/2023', '52-2023' => '25/12/2023 - 31/12/2023', )
Output for 7.4.4, 8.0.15, 8.0.22, 8.1.2

Process exited with code 137.

preferences:
129.07 ms | 409 KiB | 5 Q