3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tz = new DateTimeZone("UTC"); //lets say he chosed the service on Monday and Tuesday and Wednesday $days = "Monday ,Tuesday, Wednesday";// <-- change to user input $planDays = translateWeekDaysToNumbers($days); $planName = "Weekly";// <- change as user input if($planName == 'Weekly'){ $weekOrMonth = "week"; } else if ($planName == 'Monthly'){ $weekOrMonth = "month"; } else { //TODO: throw error } $startString = "2019-02-01 00:00:00"; // <- change later to "now" $startDate = new DateTime($startString, $tz); $afterMonth = new DateTime("@" . strtotime("+1 $weekOrMonth", $startDate->format("U"))); $numberOfDays = $afterMonth->diff($startDate)->days; $daysOfService = 0; // what we need to calculate for($i = 0; $i<$numberOfDays; $i++){ $dateInterval = new DateInterval("P{$i}D"); $startDate->add($dateInterval); if (in_array($startDate->format("w"), $planDays)) $daysOfService ++; $startDate->sub($dateInterval);//reset to first day } $pro_price = 100;// <--- change to your price from the DB $totalPrice = $daysOfService * $pro_price; echo $daysOfService . "\n"; echo $totalPrice . "\n"; exit; function translateWeekDaysToNumbers(string $days) { //dont change the numbers as they are the given by ->format("w") $daysNumbers = [ "sunday" => 0, "monday" => 1, "tuesday" => 2, "wednesday" => 3, "thursday" => 4, "friday" => 5, "saturday" => 6 ]; $days = explode(",", $days); $planDays = []; foreach($days as $day){ $day = strtolower(trim($day)); if (isset($daysNumbers[$day])) $planDays[] = $daysNumbers[$day]; } return $planDays; }

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.3.70.0070.01417.00
8.3.60.0040.01316.63
8.3.50.0090.00916.46
8.3.40.0090.00618.86
8.3.30.0070.00719.00
8.3.20.0070.00021.76
8.3.10.0000.00721.85
8.3.00.0000.00822.57
8.2.190.0060.00916.88
8.2.180.0100.01018.54
8.2.170.0140.00722.96
8.2.160.0110.00419.45
8.2.150.0000.00924.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0070.00021.17
8.2.110.0090.00021.17
8.2.100.0090.00418.39
8.2.90.0180.00718.35
8.2.80.0180.00718.31
8.2.70.0200.00318.35
8.2.60.0150.00618.45
8.2.50.0170.00518.33
8.2.40.0150.00518.82
8.2.30.0170.00318.79
8.2.20.0110.00618.36
8.2.10.0170.00418.74
8.2.00.0160.00718.82
8.1.280.0040.01525.92
8.1.270.0040.00422.14
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00322.20
8.1.230.0190.00319.83
8.1.220.0140.00718.22
8.1.210.0200.00218.62
8.1.200.0200.00318.13
8.1.190.0180.00218.12
8.1.180.0140.00818.33
8.1.170.0180.00618.60
8.1.160.0160.00620.26
8.1.150.0160.00718.66
8.1.140.0210.00319.27
8.1.130.0190.00419.04
8.1.120.0160.00618.21
8.1.110.0200.00218.17
8.1.100.0140.00618.16
8.1.90.0150.00518.20
8.1.80.0210.00118.22
8.1.70.0170.00418.19
8.1.60.0200.00218.22
8.1.50.0170.00418.19
8.1.40.0110.01018.16
8.1.30.0150.00518.23
8.1.20.0180.00718.19
8.1.10.0200.00218.23
8.1.00.0220.00218.22
8.0.300.0170.00419.61
8.0.290.0170.00417.96
8.0.280.0140.00618.48
8.0.270.0200.00317.98
8.0.260.0150.00518.98
8.0.250.0160.00518.05
8.0.240.0170.00518.02
8.0.230.0190.00418.04
8.0.220.0190.00218.02
8.0.210.0130.00718.02
8.0.200.0170.00318.03
8.0.190.0170.00418.08
8.0.180.0180.00418.01
8.0.170.0160.00418.05
8.0.160.0150.00618.03
8.0.150.0160.00418.04
8.0.140.0160.00518.02
8.0.130.0160.00416.82
8.0.120.0170.00418.05
8.0.110.0160.00418.01
8.0.100.0170.00518.02
8.0.90.0150.00617.97
8.0.80.0150.01118.03
8.0.70.0180.00418.05
8.0.60.0140.00718.04
8.0.50.0200.00218.06
8.0.30.0150.00717.91
8.0.20.0230.00418.09
8.0.10.0240.00518.09
8.0.00.0180.00617.83
7.4.330.0130.00317.48
7.4.320.0180.00417.90
7.4.300.0170.00217.90
7.4.290.0160.00417.84
7.4.280.0200.00017.91
7.4.270.0170.00317.87
7.4.260.0140.00516.77
7.4.250.0140.00617.86
7.4.240.0140.00617.59
7.4.230.0150.00517.82
7.4.220.0120.00517.58
7.4.210.0140.00717.41
7.4.200.0110.00817.87
7.4.190.0180.00718.44
7.4.180.0210.00418.44
7.4.160.0240.00318.44
7.4.150.0170.00918.09
7.4.140.0190.00618.03
7.4.130.0140.00717.82
7.4.120.0170.00717.75
7.4.110.0150.00917.77
7.4.100.0190.00217.74
7.4.90.0150.00617.80
7.4.80.0160.00718.42
7.4.70.0150.00617.76
7.4.60.0180.00317.76
7.4.50.0160.00717.69
7.4.40.0140.00717.75
7.4.30.0180.00518.09
7.4.20.0160.00718.09
7.4.10.0200.00618.09
7.4.00.0150.00617.32
7.3.330.0170.00117.88
7.3.320.0150.00416.83
7.3.310.0110.00717.85
7.3.300.0160.00317.86
7.3.290.0160.00417.81
7.3.280.0170.00917.85
7.3.270.0180.00718.09
7.3.260.0140.00817.21
7.3.250.0170.00818.09
7.3.240.0140.00717.30
7.3.230.0160.00917.76
7.3.220.0170.00618.09
7.3.210.0150.00817.78
7.3.200.0160.00517.73
7.3.190.0140.00917.78
7.3.180.0130.01117.78
7.3.170.0150.00817.74
7.3.160.0170.00517.75
7.3.150.0140.00918.09
7.3.140.0170.00918.09
7.3.130.0180.00518.09
7.3.120.0180.00718.09
7.3.110.0160.00718.09
7.3.100.0200.00518.09
7.3.90.0130.00716.88
7.3.80.0120.00716.90
7.3.70.0140.00916.90
7.3.60.0120.00916.87
7.3.50.0140.00616.91
7.3.40.0130.00816.80
7.3.30.0110.00716.91
7.3.20.0170.00416.91
7.3.10.0140.00816.88
7.3.00.0150.00816.89
7.2.340.0200.00818.09
7.2.330.0170.01117.76
7.2.320.0170.00817.75
7.2.310.0180.00817.86
7.2.300.0190.00717.82
7.2.290.0180.00717.82
7.2.280.0190.01018.09
7.2.270.0230.00918.09
7.2.260.0230.00718.09
7.2.250.0240.00418.09
7.2.240.0220.00618.09
7.2.230.0270.00418.09
7.2.220.0140.01017.00
7.2.210.0190.00317.01
7.2.200.0190.00516.96
7.2.190.0160.00917.02
7.2.180.0180.00716.94
7.2.170.0180.00717.00
7.2.160.0160.00616.97
7.2.150.0190.00717.01
7.2.140.0250.00617.05
7.2.130.0170.00817.06
7.2.120.0180.00717.00
7.2.110.0150.00916.97
7.2.100.0210.00817.00
7.2.90.0170.01016.99
7.2.80.0210.00517.03
7.2.70.0220.00717.02
7.2.60.0170.00817.08
7.2.50.0200.00716.98
7.2.40.0180.00617.00
7.2.30.0180.00617.07
7.2.20.0190.00417.16
7.2.10.0220.00716.96
7.2.00.0210.00917.02
7.1.330.0170.01118.09
7.1.320.0170.00516.55
7.1.310.0140.00816.58
7.1.300.0130.00816.54
7.1.290.0170.00716.57
7.1.280.0200.00516.51
7.1.270.0150.00816.50
7.1.260.0180.00516.56
7.1.250.0190.00716.53
7.1.240.0210.00517.09
7.1.230.0160.00817.14
7.1.220.0180.00617.14
7.1.210.0200.00617.14
7.1.200.0180.00817.10
7.1.190.0150.01017.15
7.1.180.0190.00617.08
7.1.170.0200.00517.10
7.1.160.0350.00517.14
7.1.150.0200.00617.11
7.1.140.0210.00517.12
7.1.130.0170.00717.04
7.1.120.0190.00517.10
7.1.110.0190.00817.12
7.1.100.0220.00417.12
7.1.90.0190.00517.09
7.1.80.0200.00517.15
7.1.70.0190.00617.11
7.1.60.0200.00417.05
7.1.50.0200.00617.16
7.1.40.0440.00617.13
7.1.30.0220.00417.09
7.1.20.0200.00517.14
7.1.10.0180.00817.15
7.1.00.0220.00417.13

preferences:
31.48 ms | 401 KiB | 5 Q