3v4l.org

run code in 300+ PHP versions simultaneously
<?php $firstAvailableCount = 100; $slice = 'monthly'; $countData = array(); $startDateTime = new DateTime("2016-01-01"); $endDateTime = new DateTime("2016-02-02"); fillCountMapPeriod($startDateTime,$endDateTime,$countData,$firstAvailableCount,$slice); function fillCountMapPeriod( DateTime $startDateTime, DateTime $endDateTime, array $countData, $firstAvailableCount, $slice) { if($slice == 'monthly') { $interval = new DateInterval('P1M'); $format = 'm-Y'; $startDateTime = DateTime::createFromFormat($format,$startDateTime->format($format)); } else { $interval = new DateInterval('P1W'); $format = 'W-Y'; } var_dump($startDateTime); if($startDateTime->format($format) == $endDateTime->format($format)) { var_dump($startDateTime->format($format)); return; } $endDateTime->add($interval); //var_dump($endDateTime); while($startDateTime <= $endDateTime){ var_dump($startDateTime->format("d-".$format)); $startDateTime->add($interval); } }
Output for 5.6.28, 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.31, 7.4.0 - 7.4.33, 8.0.0 - 8.0.12, 8.0.14 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-05 19:48:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "05-01-2016" string(10) "05-02-2016"
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-05 19:48:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "05-01-2016" string(10) "05-02-2016"
Output for 7.3.32 - 7.3.33, 8.0.13
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-05 18:48:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } string(10) "05-01-2016" string(10) "05-02-2016"
Output for 7.0.6
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-21 13:22:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "21-01-2016" string(10) "21-02-2016"
Output for 7.0.5
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-03 09:24:41.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "03-01-2016" string(10) "03-02-2016"
Output for 7.0.4
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-10 21:31:08.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "10-01-2016" string(10) "10-02-2016"
Output for 7.0.3
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-18 22:55:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "18-01-2016" string(10) "18-02-2016"
Output for 7.0.2
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-23 05:08:20.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "23-01-2016" string(10) "23-02-2016"
Output for 7.0.1
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-24 08:15:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "24-01-2016" string(10) "24-02-2016"
Output for 7.0.0
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-27 10:08:51.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "27-01-2016" string(10) "27-02-2016"
Output for 5.6.21
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-02 16:17:39.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "02-01-2016" string(10) "02-02-2016"
Output for 5.6.20
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-10 08:26:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "10-01-2016" string(10) "10-02-2016"
Output for 5.6.19
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-08 05:39:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "08-01-2016" string(10) "08-02-2016"
Output for 5.6.18
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-15 14:36:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "15-01-2016" string(10) "15-02-2016"
Output for 5.6.17
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-20 02:08:44.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "20-01-2016" string(10) "20-02-2016"
Output for 5.6.16
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-28 10:58:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "28-01-2016" string(10) "28-02-2016"
Output for 5.6.15
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-29 11:47:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "29-01-2016" string(10) "29-02-2016"
Output for 5.6.14
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-14 17:29:58.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "14-01-2016" string(10) "14-02-2016"
Output for 5.6.13
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-15 18:09:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "15-01-2016" string(10) "15-02-2016"
Output for 5.6.12
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-20 08:38:01.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "20-01-2016" string(10) "20-02-2016"
Output for 5.6.11
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-24 15:04:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "24-01-2016" string(10) "24-02-2016"
Output for 5.6.10
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-25 17:10:02.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "25-01-2016" string(10) "25-02-2016"
Output for 5.6.9
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-27 22:36:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "27-01-2016" string(10) "27-02-2016"
Output for 5.6.8
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-30 07:06:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "30-01-2016" string(10) "01-03-2016"
Output for 5.5.35
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-23 02:15:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "23-01-2016" string(10) "23-02-2016"
Output for 5.5.34
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-11 10:40:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "11-01-2016" string(10) "11-02-2016"
Output for 5.5.33
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-09 08:38:12.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "09-01-2016" string(10) "09-02-2016"
Output for 5.5.32
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-17 18:33:02.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "17-01-2016" string(10) "17-02-2016"
Output for 5.5.31
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-21 05:17:35.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "21-01-2016" string(10) "21-02-2016"
Output for 5.5.30
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:39:33.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016" string(10) "01-03-2016"
Output for 5.5.29
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-17 08:26:43.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "17-01-2016" string(10) "17-02-2016"
Output for 5.5.28
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-21 11:56:33.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "21-01-2016" string(10) "21-02-2016"
Output for 5.5.27
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-22 13:35:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "22-01-2016" string(10) "22-02-2016"
Output for 5.5.26
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-26 19:50:40.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "26-01-2016" string(10) "26-02-2016"
Output for 5.5.25
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-29 03:16:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "29-01-2016" string(10) "29-02-2016"
Output for 5.5.24
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-24 09:39:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "24-01-2016" string(10) "24-02-2016"

preferences:
150.46 ms | 401 KiB | 181 Q