3v4l.org

run code in 300+ PHP versions simultaneously
<?php $firstAvailableCount = 100; $slice = 'monthly'; $countData = array(); $startDateTime = new DateTime("2016-01-07"); $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."-d",$startDateTime->format($format).-"1"); $endDateTime = DateTime::createFromFormat($format."-d",$endDateTime->format($format).-"1"); } else { $interval = new DateInterval('P1W'); $format = 'W-Y'; } var_dump($startDateTime); if($startDateTime->format($format) == $endDateTime->format($format)) { var_dump($startDateTime->format($format)); return; } //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.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:52:15.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-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-01 19:52:15.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.3.32 - 7.3.33, 8.0.13
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 18:52:15.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.6
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:22:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.5
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 09:24:36.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.4
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 21:31:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.3
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 22:55:05.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.2
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:08:14.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.1
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:15:29.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 7.0.0
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:08:46.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.21
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 16:17:35.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.20
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:26:28.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.19
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:39:18.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.18
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 14:36:22.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.17
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 02:08:38.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.16
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:58:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.15
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 11:47:21.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.14
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 17:29:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.13
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 18:08:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.12
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:37:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.11
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 15:04:05.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.10
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 17:09:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.9
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 22:35:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.6.8
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 07:06:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.35
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 02:15:13.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.34
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 10:40:18.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.33
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:38:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.32
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 18:32:56.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.31
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 05:17:29.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.30
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:39:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.29
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 08:26:38.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.28
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 11:56:29.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.27
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 13:35:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.26
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 19:50:35.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.25
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 03:15:55.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"
Output for 5.5.24
object(DateTime)#4 (3) { ["date"]=> string(26) "2016-01-01 09:39:16.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(10) "01-01-2016" string(10) "01-02-2016"

preferences:
157.52 ms | 401 KiB | 182 Q