3v4l.org

run code in 300+ PHP versions simultaneously
<?php $dates[] = array("date" => "2016-02-18 02:00:00", "duration" => "600"); // 10 mins $dates[] = array("date" => "2016-02-18 02:05:00", "duration" => "300"); // 5 mins $dates[] = array("date" => "2016-02-18 02:10:00", "duration" => "600"); $dates[] = array("date" => "2016-02-18 02:25:00", "duration" => "300"); $dates[] = array("date" => "2016-02-18 02:30:00", "duration" => "600"); $alreadyChosenDates[] = array("date" => "2016-02-18 02:10:30", "duration" => "600"); // 10 mins //$alreadyChosenDates[] = array("date" => "2016-02-18 02:05:00", "duration" => "300"); // 5 mins function returnClosestTime($alreadyChosenDates, $dates){ // Set an array called $closestTime that has the time difference and the key $closestTime = [null, null]; // Check each element in array foreach($dates as $key => $date){ foreach($alreadyChosenDates as $chosenDates){ // Calculate difference between already chosen dates array and the dates array $diff = (strtotime($chosenDates["date"]) + $chosenDates["duration"]) - strtotime($date["date"]); if($diff < 0) $diff = $diff * -1; // If $closestTime is empty, populate it if($closestTime[0] === null) $closestTime = [$diff, $key]; // If $closestTime isn't empty and the current date's time difference // is smaller, populate $closestTime with the time difference and key else if($diff < $closestTime[0]) $closestTime = [$diff, $key]; } } return $dates[$closestTime[1]]; } echo "<pre>"; print_r(returnClosestTime($alreadyChosenDates, $dates)); echo "</pre>";

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.5.10.0080.00820.18
8.5.00.0090.01221.74
8.4.150.0010.00114.05
8.4.140.0150.00617.59
8.4.130.0140.00918.13
8.4.120.0130.00720.39
8.4.110.0060.00420.40
8.4.100.0100.01019.13
8.4.90.0040.00520.39
8.4.80.0110.00718.07
8.4.70.0120.00918.18
8.4.60.0150.00618.86
8.4.50.0140.00719.16
8.4.40.0150.00519.73
8.4.30.0100.01017.97
8.4.20.0130.00719.73
8.4.10.0070.01419.64
8.3.280.0120.00818.64
8.3.270.0140.00616.98
8.3.260.0130.00716.45
8.3.250.0070.00618.81
8.3.240.0130.00716.50
8.3.230.0110.00817.05
8.3.220.0090.00618.96
8.3.210.0080.01216.97
8.3.200.0090.01016.75
8.3.190.0120.00616.63
8.3.180.0050.00419.23
8.3.170.0070.00720.71
8.3.160.0160.00618.43
8.3.150.0100.00716.93
8.3.140.0030.00619.15
8.3.130.0040.00418.53
8.3.120.0030.00718.91
8.3.110.0160.00020.94
8.3.100.0050.00324.06
8.3.90.0120.00326.77
8.3.80.0060.00316.75
8.3.70.0000.01416.63
8.3.60.0120.00616.75
8.3.50.0110.01022.17
8.3.40.0140.00319.01
8.3.30.0170.00318.83
8.3.20.0090.00920.96
8.3.10.0140.00421.78
8.3.00.0040.00421.76
8.2.290.0130.00720.18
8.2.280.0050.00418.80
8.2.270.0120.00620.48
8.2.260.0090.00916.72
8.2.250.0200.00016.62
8.2.240.0070.01318.93
8.2.230.0100.01022.58
8.2.220.0030.00637.54
8.2.210.0050.00326.77
8.2.200.0060.00318.55
8.2.190.0080.00816.63
8.2.180.0140.00316.63
8.2.170.0110.00322.96
8.2.160.0160.00322.27
8.2.150.0150.00424.18
8.2.140.0070.01324.66
8.2.130.0070.00026.16
8.2.120.0070.00021.07
8.2.110.0040.00420.52
8.2.100.0090.00618.03
8.2.90.0040.00418.22
8.2.80.0040.00718.00
8.2.70.0000.01018.00
8.2.60.0000.00917.88
8.2.50.0020.00518.16
8.2.40.0060.00319.57
8.2.30.0040.00417.98
8.2.20.0050.00218.13
8.2.10.0040.00418.29
8.2.00.0040.00418.01
8.1.330.0110.00821.99
8.1.320.0090.01016.00
8.1.310.0060.00318.43
8.1.300.0060.00318.17
8.1.290.0060.00330.84
8.1.280.0070.01325.92
8.1.270.0040.00422.23
8.1.260.0120.00326.35
8.1.250.0050.00328.09
8.1.240.0090.00022.61
8.1.230.0000.01120.90
8.1.220.0000.00817.91
8.1.210.0000.00819.04
8.1.200.0000.00817.35
8.1.190.0000.00917.35
8.1.180.0060.00318.10
8.1.170.0040.00417.65
8.1.160.0030.00618.97
8.1.150.0040.00422.05
8.1.140.0000.00819.74
8.1.130.0070.00017.76
8.1.120.0000.00817.71
8.1.110.0030.00517.69
8.1.100.0040.00417.68
8.1.90.0000.00717.70
8.1.80.0030.00417.62
8.1.70.0070.00317.70
8.1.60.0030.00517.79
8.1.50.0060.00617.61
8.1.40.0100.00217.71
8.1.30.0040.00417.82
8.1.20.0040.00417.83
8.1.10.0040.00417.75
8.1.00.0090.00017.70
8.0.300.0030.00519.74
8.0.290.0000.00817.13
8.0.280.0070.00318.19
8.0.270.0000.01020.00
8.0.260.0030.00317.39
8.0.250.0000.00717.29
8.0.240.0040.00417.14
8.0.230.0070.00017.26
8.0.220.0000.00717.20
8.0.210.0000.00717.05
8.0.200.0070.00017.15
8.0.190.0030.00617.25
8.0.180.0030.00617.23
8.0.170.0080.00017.28
8.0.160.0070.00017.12
8.0.150.0030.00517.07
8.0.140.0040.00417.07
8.0.130.0060.00013.55
8.0.120.0080.00017.07
8.0.110.0000.00717.14
8.0.100.0040.00417.13
8.0.90.0040.00417.07
8.0.80.0030.01217.24
8.0.70.0070.00017.05
8.0.60.0050.00317.14
8.0.50.0000.00817.25
8.0.30.0080.00817.12
8.0.20.0100.00917.43
8.0.10.0000.00817.20
8.0.00.0150.00317.13
7.4.330.0000.00515.55
7.4.320.0070.00016.75
7.4.300.0060.00016.77
7.4.290.0000.00716.80
7.4.280.0030.00516.66
7.4.270.0070.00016.69
7.4.260.0050.00516.70
7.4.250.0000.00716.48
7.4.240.0040.00416.67
7.4.230.0040.00416.86
7.4.220.0070.01116.88
7.4.210.0130.00316.74
7.4.200.0030.00316.56
7.4.160.0090.01016.73
7.4.150.0120.00917.40
7.4.140.0140.00517.86
7.4.130.0070.01016.75
7.4.120.0080.01016.65
7.4.110.0040.01416.87
7.4.100.0090.00916.81
7.4.90.0090.00916.77
7.4.80.0090.00919.39
7.4.70.0030.01316.63
7.4.60.0090.01316.80
7.4.50.0040.01116.52
7.4.40.0110.01116.69
7.4.30.0130.00916.79
7.4.00.0090.00614.94
7.3.330.0000.00613.39
7.3.320.0000.00613.39
7.3.310.0070.00016.42
7.3.300.0050.00316.41
7.3.290.0060.01216.48
7.3.280.0100.00816.43
7.3.270.0170.00017.40
7.3.260.0110.00616.71
7.3.250.0080.00916.60
7.3.240.0150.00616.67
7.3.230.0090.00916.94
7.3.210.0080.00816.49
7.3.200.0090.01316.70
7.3.190.0130.00416.58
7.3.180.0120.00916.64
7.3.170.0150.00916.61
7.3.160.0080.00816.84
7.3.120.0100.00715.07
7.3.110.0030.01315.14
7.3.100.0060.00315.15
7.3.90.0030.01214.85
7.3.80.0110.00414.90
7.3.70.0110.00615.02
7.3.60.0060.00315.07
7.3.50.0060.00314.98
7.3.40.0030.01015.01
7.3.30.0070.01015.07
7.3.20.0070.01016.82
7.3.10.0070.00816.35
7.3.00.0040.00816.67
7.2.330.0040.01416.95
7.2.320.0110.00716.97
7.2.310.0070.01116.84
7.2.300.0100.00716.61
7.2.290.0070.01016.78
7.2.240.0080.01115.30
7.2.230.0040.01415.27
7.2.220.0050.00515.36
7.2.210.0130.00315.35
7.2.200.0090.00915.16
7.2.190.0060.00915.09
7.2.180.0040.01215.26
7.2.170.0140.00715.36
7.2.160.0060.00615.14
7.2.150.0060.00917.29
7.2.140.0090.00617.25
7.2.130.0060.00717.00
7.2.120.0030.00816.90
7.2.110.0090.00816.84
7.2.100.0040.00816.80
7.2.90.0040.00716.96
7.2.80.0060.00916.86
7.2.70.0070.00917.05
7.2.60.0070.00517.07
7.2.50.0060.00517.11
7.2.40.0070.00817.03
7.2.30.0080.00616.75
7.2.20.0080.00816.92
7.2.10.0040.01116.92
7.2.00.0080.00517.93
7.1.330.0090.00916.09
7.1.320.0000.01415.87
7.1.310.0030.01315.72
7.1.300.0030.01015.82
7.1.290.0000.01416.10
7.1.280.0090.00915.93
7.1.270.0070.00315.96
7.1.260.0030.01016.09
7.1.250.0100.00915.77
7.1.200.0100.00016.06
7.1.70.0030.00517.37
7.1.60.0000.01017.30
7.1.50.0070.01417.32
7.1.40.0120.00916.79
7.1.30.0070.01317.00
7.1.20.0100.00716.98
7.1.10.0080.00016.83
7.1.00.0110.00317.00
7.0.200.0000.01516.99
7.0.190.0000.00816.68
7.0.180.0030.01316.59
7.0.170.0060.00316.51
7.0.160.0030.01216.59
7.0.150.0000.00816.52
7.0.140.0040.00416.63
7.0.130.0070.00416.75
7.0.120.0030.00616.80
7.0.110.0030.01316.48
7.0.100.0040.01116.59
7.0.90.0060.01016.57
7.0.80.0000.00816.57
7.0.70.0000.01516.52
7.0.60.0070.00716.38
7.0.50.0020.01016.36
7.0.40.0070.00314.82
7.0.30.0040.00414.82
7.0.20.0040.00414.82
7.0.10.0070.00714.82
7.0.00.0060.00614.82
5.6.300.0030.04520.81
5.6.290.0000.04620.79
5.6.280.0030.08520.98
5.6.270.0000.04521.04
5.6.260.0070.03920.91
5.6.250.0030.07220.89
5.6.240.0100.07320.87
5.6.230.0070.08320.94
5.6.220.0030.06720.87
5.6.210.0100.07420.63
5.6.200.0000.08420.78
5.6.190.0130.04920.96
5.6.180.0070.05720.84
5.6.170.0000.06420.84
5.6.160.0070.08020.96
5.6.150.0070.08220.82
5.6.140.0060.03720.82
5.6.130.0030.05920.96
5.6.120.0030.08521.03
5.6.110.0100.04420.95
5.6.100.0070.08020.93
5.6.90.0070.08720.81
5.6.80.0070.03820.37
5.6.70.0130.03720.34
5.6.60.0000.04420.14
5.6.50.0000.04420.31
5.6.40.0130.03220.32
5.6.30.0070.03520.29
5.6.20.0030.03920.18
5.6.10.0000.08020.19
5.6.00.0000.05020.26

preferences:
38.89 ms | 403 KiB | 5 Q