3v4l.org

run code in 300+ PHP versions simultaneously
<?php function nearest(array $arr, $needle) { $closest = current($arr); foreach ($arr as $val) { if ($val === $needle) { return $val; // found it :) } if ($val > $closest && $val < $needle) { // we found something closer and less than the needle, so use it $closest = $val; } } // we've reached the end, so return the closest solution return $closest; } $array = array(2012, 2013, 2015, 2016, 2018); $needle = 2011; print nearest($array, $needle);

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.60.0180.00018.42
8.3.50.0050.01122.11
8.3.40.0060.01318.71
8.3.30.0170.00019.04
8.3.20.0090.00620.20
8.3.10.0080.00022.10
8.3.00.0040.00422.43
8.2.180.0160.00316.32
8.2.170.0120.00322.96
8.2.160.0100.00320.94
8.2.150.0040.00424.18
8.2.140.0120.00324.66
8.2.130.0000.00726.16
8.2.120.0040.00419.08
8.2.110.0050.00522.22
8.2.100.0130.00019.64
8.2.90.0050.00319.21
8.2.80.0080.00018.00
8.2.70.0040.00417.50
8.2.60.0070.00017.93
8.2.50.0040.00418.07
8.2.40.0040.00418.22
8.2.30.0000.00717.93
8.2.20.0070.00017.70
8.2.10.0040.00419.61
8.2.00.0080.00017.68
8.1.280.0040.01125.92
8.1.270.0120.00321.98
8.1.260.0070.00026.35
8.1.250.0030.01028.09
8.1.240.0070.00323.98
8.1.230.0080.00318.97
8.1.220.0000.00817.74
8.1.210.0090.00018.77
8.1.200.0060.00317.35
8.1.190.0080.00017.55
8.1.180.0030.00618.73
8.1.170.0030.00518.63
8.1.160.0030.00622.02
8.1.150.0040.00418.63
8.1.140.0040.00417.36
8.1.130.0040.00417.85
8.1.120.0070.00017.36
8.1.110.0060.00317.40
8.1.100.0040.00317.44
8.1.90.0000.00717.39
8.1.80.0000.00817.53
8.1.70.0000.00817.35
8.1.60.0070.00017.63
8.1.50.0040.00417.57
8.1.40.0030.00617.52
8.1.30.0030.00617.56
8.1.20.0040.00417.65
8.1.10.0000.00817.40
8.1.00.0050.00317.43
8.0.300.0060.00318.77
8.0.290.0040.00417.13
8.0.280.0000.00718.49
8.0.270.0000.00717.26
8.0.260.0000.00716.74
8.0.250.0000.00816.98
8.0.240.0030.00316.94
8.0.230.0000.00816.86
8.0.220.0030.00316.89
8.0.210.0000.00616.80
8.0.200.0060.00016.97
8.0.190.0070.00016.82
8.0.180.0000.00716.91
8.0.170.0050.00216.86
8.0.160.0040.00416.87
8.0.150.0080.00016.71
8.0.140.0040.00416.73
8.0.130.0000.00613.40
8.0.120.0000.00716.91
8.0.110.0060.00316.83
8.0.100.0040.00416.88
8.0.90.0040.00416.71
8.0.80.0030.01316.90
8.0.70.0040.00416.77
8.0.60.0020.00516.77
8.0.50.0000.00716.95
8.0.30.0050.01416.92
8.0.20.0080.01017.40
8.0.10.0000.00717.00
8.0.00.0090.01116.70
7.4.330.0000.00515.14
7.4.320.0030.00316.49
7.4.300.0030.00316.50
7.4.290.0030.00316.40
7.4.280.0000.00716.50
7.4.270.0030.00316.44
7.4.260.0030.00316.35
7.4.250.0080.00016.52
7.4.240.0020.00516.54
7.4.230.0030.00316.57
7.4.220.0130.00316.56
7.4.210.0030.01116.50
7.4.200.0030.00516.65
7.4.190.0070.00016.63
7.4.160.0080.00816.61
7.4.150.0030.01317.40
7.4.140.0120.00517.86
7.4.130.0130.00316.78
7.4.120.0090.00816.48
7.4.110.0100.00716.54
7.4.100.0160.00616.70
7.4.90.0150.00916.27
7.4.80.0140.00319.39
7.4.70.0130.00316.39
7.4.60.0170.00016.33
7.4.50.0020.00216.55
7.4.40.0080.00522.77
7.4.30.0070.01016.44
7.4.00.0090.00614.73
7.3.330.0060.00013.40
7.3.320.0000.00513.24
7.3.310.0070.00016.19
7.3.300.0000.00616.33
7.3.290.0090.00616.41
7.3.280.0090.00816.34
7.3.270.0090.00917.40
7.3.260.0110.00616.47
7.3.250.0070.01216.53
7.3.240.0140.00916.32
7.3.230.0080.01016.39
7.3.210.0070.01016.57
7.3.200.0170.00719.39
7.3.190.0040.01316.55
7.3.180.0110.00616.36
7.3.170.0080.00716.39
7.3.160.0120.00416.65
7.3.120.0040.01215.02
7.3.10.0120.00016.32
7.3.00.0100.00316.67
7.2.330.0090.00916.67
7.2.320.0090.00616.73
7.2.310.0060.01016.45
7.2.300.0030.01916.61
7.2.290.0150.00316.82
7.2.130.0060.00316.79
7.2.120.0150.00017.02
7.2.110.0060.00317.02
7.2.100.0000.00917.05
7.2.90.0030.00616.84
7.2.80.0030.01016.77
7.2.70.0070.00316.96
7.2.60.0040.00416.97
7.2.50.0060.00616.86
7.2.40.0030.01016.96
7.2.30.0100.00317.05
7.2.20.0100.00616.76
7.2.10.0000.01316.94
7.2.00.0080.00618.28
7.1.250.0000.00915.82
7.1.100.0000.01418.19
7.1.70.0030.00717.19
7.1.60.0060.01319.82
7.1.50.0070.01116.93
7.1.00.0030.07722.48
7.0.200.0000.01216.88
7.0.140.0000.07722.10
7.0.60.0070.08319.90
7.0.50.0070.04017.83
7.0.40.0100.08320.21
7.0.30.0270.07020.21
7.0.20.0270.07720.30
7.0.10.0230.04720.09
7.0.00.0030.04020.23
5.6.280.0000.07720.78
5.6.210.0070.08320.51
5.6.200.0070.04718.28
5.6.190.0030.05320.55
5.6.180.0200.03720.58
5.6.170.0370.07320.48
5.6.160.0100.08020.46
5.6.150.0000.04318.19
5.6.140.0070.04018.13
5.6.130.0130.07718.14
5.6.120.0100.04321.00
5.6.110.0130.06720.89
5.6.100.0130.07721.14
5.6.90.0000.04320.98
5.6.80.0070.08320.54
5.6.70.3030.03320.39
5.5.350.0170.05020.53
5.5.340.0100.03317.98
5.5.330.0130.04320.21
5.5.320.0400.05720.35
5.5.310.0270.04020.40
5.5.300.0130.07317.92
5.5.290.0070.04017.96
5.5.280.0030.05320.88
5.5.270.0130.05720.84
5.5.260.0100.07720.65
5.5.250.0100.08020.78
5.5.240.0130.07020.16
5.4.450.0400.07019.18
5.4.440.0270.07319.39
5.4.430.0300.07019.56
5.4.420.0230.06319.17
5.4.410.0300.07019.14
5.4.400.0300.06019.00
5.4.390.0330.07019.13
5.4.380.0270.05718.95
5.4.370.0400.06018.88
5.4.360.0370.06019.31
5.4.350.0400.06019.06
5.4.340.0330.05019.15
5.4.320.0270.04319.09
5.4.310.0200.04019.20
5.4.300.0330.05718.98
5.4.290.0400.06318.98
5.4.280.0270.07319.21
5.4.270.0370.07018.99
5.4.260.0400.05019.16
5.4.250.0300.06318.85
5.4.240.0300.06718.99
5.4.230.0330.06719.13
5.4.220.0330.04719.13
5.4.210.0300.03319.13
5.4.200.0270.06318.97
5.4.190.0370.05319.21
5.4.180.0200.08318.86
5.4.170.0200.05019.21
5.4.160.0270.04019.13
5.4.150.0400.05018.93
5.4.140.0330.03016.36
5.4.130.0300.06716.33
5.4.120.0300.06016.51
5.4.110.0230.07716.28
5.4.100.0270.06716.45
5.4.90.0370.04316.51
5.4.80.0230.05316.57
5.4.70.0300.04316.43
5.4.60.0270.05016.25
5.4.50.0270.07316.24
5.4.40.0200.05716.21
5.4.30.0300.03016.48
5.4.20.0270.04716.16
5.4.10.0330.06016.42
5.4.00.0370.03715.78
5.3.290.0230.03714.60
5.3.280.0300.06714.57
5.3.270.0330.07014.62
5.3.260.0270.04014.76
5.3.250.0200.05314.57
5.3.240.0270.04314.77
5.3.230.0370.06314.57
5.3.220.0330.07014.74
5.3.210.0400.06014.68
5.3.200.0230.06714.57
5.3.190.0300.06714.57
5.3.180.0200.08014.55
5.3.170.0270.05714.64
5.3.160.0370.06714.56
5.3.150.0400.05314.71
5.3.140.0370.06314.47
5.3.130.0270.07014.52
5.3.120.0330.07014.46
5.3.110.0270.04314.52
5.3.100.0330.06714.11
5.3.90.0270.04714.10
5.3.80.0270.03313.94
5.3.70.0270.03313.94

preferences:
39.45 ms | 401 KiB | 5 Q