3v4l.org

run code in 300+ PHP versions simultaneously
<?php function countDaysByName($dayName, \DateTime $start, \DateTime $end) { $count = 0; $interval = new \DateInterval('P1D'); $period = new \DatePeriod($start, $interval, $end); foreach($period as $day){ if($day->format('D') === ucfirst(substr($dayName, 0, 3))){ $count ++; } } return $count; } echo countDaysByName('wednesday', new \DateTime(2016-01-18), new \DateTime(2016-01-23)); echo var_dump(new \DateTime(2016-18-01));
Output for 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
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-01-16 13:29:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
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 0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-01-16 13:29:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.3.32 - 7.3.33, 8.0.13
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-01-16 12:29:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }
Output for 7.0.6
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-05-21 13:54:02.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.5
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-04-03 09:50:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.4
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-10 21:58:19.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.3
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-18 23:26:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.2
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-23 05:40:16.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.1
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-24 08:43:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.0
0object(DateTime)#4 (3) { ["date"]=> string(26) "1997-03-27 10:36:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.21
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-05-02 16:45:17.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.20
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-10 08:53:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.19
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-08 06:08:15.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.18
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-15 15:06:44.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.17
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-20 02:38:51.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.16
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-28 11:25:55.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.15
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-29 12:15:26.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.14
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-14 17:57:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.13
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-15 18:36:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.12
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-20 09:07:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.11
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-24 15:33:10.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.10
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-25 17:38:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.9
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-27 23:06:58.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.8
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-30 07:33:30.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.35
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-05-23 02:49:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.34
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-11 11:08:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.33
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-09 09:07:54.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.32
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-17 19:05:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.31
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-03-21 05:51:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.30
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-01 14:06:55.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.29
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-17 08:54:37.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.28
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-21 12:26:43.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.27
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-22 14:04:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.26
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-26 20:20:13.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.25
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-04-29 03:46:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.24
0object(DateTime)#1 (3) { ["date"]=> string(26) "1997-05-24 16:52:20.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }

preferences:
167.58 ms | 401 KiB | 181 Q