3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Add days without specific days of the week * * @param DateTime $startDate start Date * @param int $days number of days * @param array $withoutDays array with elements "Mon", "Tue", "Wed", "Thu", "Fri", "Sat","Sun" * @return DateTime */ function addDaysWithout(DateTime $startDate ,int $days, array $withoutDays = []) : DateTime { //validate $withoutDays $validWeekDays = 7 - count($withoutDays); $validIdentifiers = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat","Sun"]; if($validWeekDays <= 0 OR $withoutDays != array_intersect($withoutDays,$validIdentifiers)){ $msg = 'Invalid Argument "'.implode(',',$withoutDays).'" in withoutDays'; throw new \InvalidArgumentException($msg); } $start = clone $startDate; $fullWeeks = (int)($days/$validWeekDays)-1; if($fullWeeks > 0){ $start ->modify($fullWeeks.' weeks'); $days -= $fullWeeks * $validWeekDays; } while($days){ $start->modify('+1 Day'); if(!in_array($start->format('D'),$withoutDays)){ --$days; } } return $start; } $start = date_create('2022-09-05'); $dt = addDaysWithout($start,30,["Sun"]); var_dump($dt); //object(DateTime)#3 (3) { ["date"]=> string(26) "2022-10-10 00:00:00.000000" $start = date_create('2022-09-05'); $dt = addDaysWithout($start,30,["Mon","Sun"]); var_dump($dt); //object(DateTime)#3 (3) { ["date"]=> string(26) "2022-10-15

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.4.140.0100.01217.56
8.4.130.0130.00718.63
8.4.120.0140.00619.95
8.4.110.0090.01219.59
8.4.100.0060.00418.14
8.4.90.0140.00620.38
8.4.80.0080.00519.16
8.4.70.0140.00918.94
8.4.60.0100.01118.97
8.4.50.0050.00420.66
8.4.40.0100.01018.11
8.4.30.0100.00018.83
8.4.20.0130.00318.63
8.4.10.0060.00322.23
8.3.270.0140.00916.62
8.3.260.0110.00816.91
8.3.250.0120.00818.89
8.3.240.0100.01016.76
8.3.230.0120.00816.73
8.3.220.0130.00618.92
8.3.210.0090.00717.04
8.3.200.0140.00716.74
8.3.190.0110.00719.06
8.3.180.0110.00918.91
8.3.170.0090.00620.88
8.3.160.0110.00717.35
8.3.150.0140.00419.23
8.3.140.0150.00416.80
8.3.130.0030.00618.47
8.3.120.0060.00320.71
8.3.110.0000.00920.94
8.3.100.0050.00516.61
8.3.90.0040.00426.77
8.3.80.0070.00316.75
8.3.70.0110.00416.88
8.3.60.0090.00616.74
8.3.50.0110.00718.35
8.3.40.0120.00320.21
8.3.30.0170.00318.92
8.3.20.0030.00524.18
8.3.10.0040.00424.66
8.3.00.0000.00826.16
8.2.290.0120.00816.90
8.2.280.0100.00920.43
8.2.270.0050.00320.88
8.2.260.0070.01316.83
8.2.250.0040.00419.11
8.2.240.0060.00317.59
8.2.230.0100.01022.58
8.2.220.0100.01024.06
8.2.210.0060.00326.77
8.2.200.0000.00918.54
8.2.190.0130.00317.13
8.2.180.0170.00325.92
8.2.170.0140.00722.96
8.2.160.0070.01022.96
8.2.150.0000.00825.66
8.2.140.0090.00024.66
8.2.130.0050.00226.16
8.2.120.0000.00826.16
8.2.110.0060.00320.50
8.2.100.0030.00918.15
8.2.90.0040.00418.00
8.2.80.0040.00418.29
8.2.70.0060.00317.75
8.2.60.0040.00417.75
8.2.50.0000.00818.05
8.2.40.0030.00618.28
8.2.30.0040.00418.32
8.2.20.0040.00419.43
8.2.10.0000.00818.26
8.2.00.0080.00019.34
8.1.330.0150.00416.15
8.1.320.0110.00918.20
8.1.310.0110.00816.94
8.1.300.0040.00416.16
8.1.290.0100.00030.84
8.1.280.0090.00625.92
8.1.270.0040.00424.66
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00522.19
8.1.230.0080.00421.03
8.1.220.0030.00618.03
8.1.210.0040.00418.77
8.1.200.0070.00317.60
8.1.190.0040.00417.60
8.1.180.0050.00318.10
8.1.170.0060.00317.62
8.1.160.0000.00719.13
8.1.150.0040.00418.82
8.1.140.0040.00417.69
8.1.130.0000.00718.93
8.1.120.0040.00417.77
8.1.110.0030.00517.61
8.1.100.0050.00517.69
8.1.90.0000.00717.66
8.1.80.0000.00717.66
8.1.70.0120.00317.74
8.1.60.0180.00017.82
8.1.50.0000.01717.65
8.1.40.0110.00617.59
8.1.30.0130.00417.71
8.1.20.0150.00317.74
8.1.10.0130.00417.79
8.1.00.0080.00717.73
8.0.300.0070.00020.16
8.0.290.0050.00317.00
8.0.280.0040.00418.49
8.0.270.0040.00417.14
8.0.260.0000.00718.53
8.0.250.0080.00017.24
8.0.240.0030.00317.17
8.0.230.0030.00917.25
8.0.220.0100.00517.06
8.0.210.0110.00517.14
8.0.200.0110.00417.25
8.0.190.0130.00317.27
8.0.180.0130.00317.20
8.0.170.0090.00617.11
8.0.160.0090.00617.11
8.0.150.0160.00017.19
8.0.140.0100.00517.11
8.0.130.0110.00417.02
8.0.120.0160.00017.04
8.0.110.0110.00417.07
8.0.100.0080.00817.25
8.0.90.0100.00517.11
8.0.80.0120.00517.18
8.0.70.0130.00317.05
8.0.60.0110.00417.09
8.0.50.0160.00017.09
8.0.30.0130.00317.05
8.0.20.0100.00617.00
8.0.10.0060.01117.32
7.4.330.0000.00515.55
7.4.320.0000.00716.69
7.4.300.0000.00916.63
7.4.290.0080.00816.79
7.4.280.0100.00616.64
7.4.270.0040.01316.82
7.4.260.0110.00516.68
7.4.250.0120.00616.78
7.4.240.0100.00716.76
7.4.230.0100.00716.73
7.4.220.0130.00316.68
7.4.210.0120.00416.58
7.4.200.0150.00016.79
7.4.190.0090.00516.84
7.4.180.0080.00516.74
7.4.160.0060.00616.80
7.4.150.0090.00416.70
7.4.140.0060.00616.66
7.4.130.0070.00716.72
7.4.120.0080.00516.52
7.4.110.0120.00416.55
7.4.100.0110.00416.53
7.4.90.0000.01216.45
7.4.80.0130.00016.60
7.4.70.0080.00516.64
7.4.60.0100.00316.49
7.4.50.0080.00416.63
7.4.40.0070.00716.45
7.4.30.0130.00016.62
7.4.20.0100.00316.49
7.4.10.0040.00816.67
7.4.00.0080.00416.63

preferences:
104.58 ms | 403 KiB | 5 Q