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:15:00", "duration" => "300"); $dates[] = array("date" => "2016-02-18 02:20: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:05:00", "duration" => "300"); // 10 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]]; } $alreadyChosenDates[] = returnClosestTime($alreadyChosenDates, $dates); echo "<pre>"; print_r($alreadyChosenDates); 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.0110.00720.25
8.5.00.0120.00921.88
8.4.150.0030.00014.05
8.4.140.0130.00717.96
8.4.130.0080.00818.63
8.4.120.0090.00824.00
8.4.110.0100.00722.11
8.4.100.0090.00817.84
8.4.90.0110.00918.90
8.4.80.0060.00219.80
8.4.70.0110.00918.13
8.4.60.0140.01123.95
8.4.50.0030.00519.02
8.4.40.0090.00617.87
8.4.30.0170.00319.61
8.4.20.0100.01019.71
8.4.10.0060.00619.96
8.3.280.0210.01218.69
8.3.270.0150.00616.82
8.3.260.0060.00516.78
8.3.250.0100.00918.85
8.3.240.0100.00917.14
8.3.230.0110.00716.64
8.3.220.0040.00317.19
8.3.210.0110.00318.70
8.3.200.0050.00316.69
8.3.190.0030.00617.27
8.3.180.0110.00818.97
8.3.170.0160.00316.51
8.3.160.0150.00317.36
8.3.150.0160.00318.98
8.3.140.0030.00618.73
8.3.130.0090.00018.42
8.3.120.0030.01220.79
8.3.110.0090.00920.94
8.3.100.0150.00018.56
8.3.90.0080.00026.77
8.3.80.0070.00319.36
8.3.70.0150.00718.68
8.3.60.0060.01216.63
8.3.50.0090.00921.94
8.3.40.0000.01519.04
8.3.30.0040.01119.17
8.3.20.0080.00019.20
8.3.10.0040.00421.85
8.3.00.0070.00022.08
8.2.290.0110.00820.34
8.2.280.0140.00818.66
8.2.270.0120.00818.45
8.2.260.0070.01016.95
8.2.250.0150.00316.61
8.2.240.0110.00419.00
8.2.230.0080.00022.58
8.2.220.0030.00924.06
8.2.210.0050.00326.77
8.2.200.0030.00618.88
8.2.190.0180.00016.58
8.2.180.0140.00418.54
8.2.170.0060.00919.21
8.2.160.0130.00022.96
8.2.150.0000.00925.66
8.2.140.0050.00324.66
8.2.130.0070.00026.16
8.2.120.0050.00519.06
8.2.110.0070.00319.27
8.2.100.0040.00817.97
8.2.90.0080.00019.35
8.2.80.0030.00618.09
8.2.70.0040.00418.00
8.2.60.0040.00418.16
8.2.50.0030.00618.07
8.2.40.0000.00818.47
8.2.30.0040.00418.32
8.2.20.0000.00818.13
8.2.10.0050.00318.26
8.2.00.0040.00417.89
8.1.330.0140.00521.81
8.1.320.0110.00816.11
8.1.310.0090.00618.41
8.1.300.0090.00620.31
8.1.290.0000.00930.84
8.1.280.0090.01225.92
8.1.270.0020.00523.99
8.1.260.0080.00826.35
8.1.250.0070.00028.09
8.1.240.0060.00319.46
8.1.230.0080.00417.77
8.1.220.0000.00917.74
8.1.210.0030.00518.77
8.1.200.0060.00317.48
8.1.190.0030.00517.47
8.1.180.0000.01018.10
8.1.170.0080.00318.62
8.1.160.0030.00518.82
8.1.150.0000.00720.16
8.1.140.0040.00419.59
8.1.130.0020.00517.71
8.1.120.0050.00217.70
8.1.110.0000.00717.70
8.1.100.0040.00417.67
8.1.90.0040.00417.64
8.1.80.0050.00317.55
8.1.70.0030.00817.69
8.1.60.0050.00317.77
8.1.50.0000.00917.55
8.1.40.0000.00817.71
8.1.30.0000.00817.70
8.1.20.0040.00417.72
8.1.10.0030.00517.62
8.1.00.0030.00617.73
8.0.300.0090.00018.77
8.0.290.0050.00316.88
8.0.280.0000.00818.54
8.0.270.0070.00017.35
8.0.260.0050.00517.12
8.0.250.0030.00517.15
8.0.240.0040.00417.27
8.0.230.0070.00017.22
8.0.220.0000.00717.21
8.0.210.0000.00817.13
8.0.200.0030.00617.17
8.0.190.0050.00217.20
8.0.180.0000.00717.23
8.0.170.0070.00017.09
8.0.160.0030.00317.23
8.0.150.0040.00416.98
8.0.140.0040.00417.06
8.0.130.0030.00313.57
8.0.120.0040.00417.12
8.0.110.0040.00417.02
8.0.100.0000.00817.12
8.0.90.0020.00516.98
8.0.80.0060.00917.18
8.0.70.0000.00717.23
8.0.60.0000.00717.05
8.0.50.0050.00317.00
8.0.30.0100.00817.31
8.0.20.0120.00817.40
8.0.10.0080.00017.30
8.0.00.0120.00617.18
7.4.330.0050.00015.55
7.4.320.0040.00416.76
7.4.300.0000.00616.76
7.4.290.0000.00716.77
7.4.280.0000.00816.75
7.4.270.0040.00416.66
7.4.260.0030.00316.63
7.4.250.0030.00316.67
7.4.240.0030.00316.71
7.4.230.0070.00016.41
7.4.220.0180.00016.79
7.4.210.0110.00416.79
7.4.200.0000.00716.55
7.4.160.0130.00616.65
7.4.150.0100.00717.40
7.4.140.0130.00517.86
7.4.130.0120.00816.83
7.4.120.0090.00716.64
7.4.110.0030.01316.95
7.4.100.0150.00316.80
7.4.90.0000.01616.92
7.4.80.0100.00719.39
7.4.70.0060.01016.85
7.4.60.0130.00316.61
7.4.50.0050.00516.73
7.4.40.0170.00016.61
7.4.30.0120.00416.44
7.4.00.0070.01014.83
7.3.330.0050.00013.52
7.3.320.0000.00613.31
7.3.310.0040.00416.40
7.3.300.0040.00416.54
7.3.290.0050.01116.44
7.3.280.0100.00916.46
7.3.270.0120.00617.40
7.3.260.0060.01516.63
7.3.250.0090.01016.53
7.3.240.0100.01116.58
7.3.230.0030.01216.61
7.3.210.0150.00916.60
7.3.200.0180.00016.55
7.3.190.0030.01516.59
7.3.180.0060.01116.66
7.3.170.0130.00616.54
7.3.160.0040.01216.74
7.2.330.0110.00716.97
7.2.320.0190.00316.84
7.2.310.0030.01516.87
7.2.300.0160.00616.83
7.2.290.0100.00716.82
7.2.60.0240.00717.06
7.2.50.0060.01016.90
7.2.00.0060.00819.75
7.1.200.0060.00315.98
7.1.70.0000.00817.47
7.1.60.0070.01117.25
7.1.00.0070.07322.44
7.0.200.0360.00614.98
7.0.120.0000.06322.14
7.0.110.0100.05722.11
7.0.100.0070.05721.96
7.0.90.0070.06022.06
7.0.80.0130.05022.06
7.0.70.0100.05322.10
7.0.60.0130.05021.95
7.0.50.0030.06322.08
7.0.40.0000.06322.06
7.0.30.0030.06022.08
7.0.20.0100.05722.14
7.0.10.0130.05022.11
7.0.00.0070.05721.98
5.6.270.0130.04721.09
5.6.260.0130.05721.07
5.6.250.0070.05721.05
5.6.240.0130.05320.86
5.6.230.0030.06320.83
5.6.220.0070.05721.02
5.6.210.0100.05320.85
5.6.200.0030.06320.93
5.6.190.0200.05720.93
5.6.180.0070.05720.84
5.6.170.0070.05721.02
5.6.160.0130.05020.75
5.6.150.0100.05720.84
5.6.140.0130.05320.86
5.6.130.0170.05021.00
5.6.120.0130.05320.80
5.6.110.0100.06020.82
5.6.100.0100.05720.98
5.6.90.0070.05320.84
5.6.80.0070.06020.41
5.6.70.0100.05020.38
5.6.60.0100.05320.18
5.6.50.0070.05320.41
5.6.40.0100.05320.45
5.6.30.0130.05020.11
5.6.20.0170.05720.36
5.6.10.0030.06320.42
5.6.00.0030.06020.17

preferences:
42.5 ms | 403 KiB | 5 Q