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 = 3012; 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.0150.00318.56
8.3.50.0080.01022.06
8.3.40.0110.00718.48
8.3.30.0070.01119.09
8.3.20.0040.00720.18
8.3.10.0050.00322.00
8.3.00.0040.00422.29
8.2.180.0110.00816.75
8.2.170.0090.00622.96
8.2.160.0110.00420.89
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0070.01126.16
8.2.120.0060.00319.23
8.2.110.0030.00622.11
8.2.100.0090.00319.57
8.2.90.0050.00319.08
8.2.80.0080.00017.97
8.2.70.0030.00617.49
8.2.60.0080.00018.04
8.2.50.0030.00518.07
8.2.40.0000.00818.09
8.2.30.0000.00817.97
8.2.20.0040.00417.54
8.2.10.0090.00019.52
8.2.00.0000.00817.80
8.1.280.0140.00725.92
8.1.270.0090.00022.14
8.1.260.0040.00426.35
8.1.250.0030.00628.09
8.1.240.0100.00023.99
8.1.230.0030.00719.00
8.1.220.0040.00417.78
8.1.210.0090.00018.77
8.1.200.0030.00717.35
8.1.190.0040.00417.54
8.1.180.0000.00818.67
8.1.170.0030.00518.55
8.1.160.0070.00021.93
8.1.150.0040.00418.60
8.1.140.0040.00417.45
8.1.130.0080.00017.66
8.1.120.0080.00017.39
8.1.110.0000.00817.33
8.1.100.0000.00717.38
8.1.90.0000.00717.46
8.1.80.0030.00317.45
8.1.70.0070.00017.45
8.1.60.0020.00517.57
8.1.50.0080.00017.52
8.1.40.0040.00417.46
8.1.30.0030.00517.63
8.1.20.0000.00817.66
8.1.10.0030.00617.57
8.1.00.0050.00317.36
8.0.300.0050.00318.77
8.0.290.0040.00417.16
8.0.280.0040.00418.36
8.0.270.0000.00717.18
8.0.260.0040.00416.70
8.0.250.0040.00416.94
8.0.240.0030.00316.83
8.0.230.0000.00716.93
8.0.220.0000.00616.92
8.0.210.0030.00316.83
8.0.200.0030.00316.94
8.0.190.0000.00816.82
8.0.180.0070.00016.92
8.0.170.0050.00316.88
8.0.160.0070.00016.94
8.0.150.0040.00416.81
8.0.140.0030.00616.74
8.0.130.0030.00313.28
8.0.120.0000.00816.81
8.0.110.0040.00416.91
8.0.100.0040.00416.88
8.0.90.0000.00816.82
8.0.80.0120.00316.82
8.0.70.0040.00416.89
8.0.60.0000.00716.89
8.0.50.0040.00416.87
8.0.30.0110.01217.30
8.0.20.0040.01417.41
8.0.10.0040.00416.96
8.0.00.0090.01416.65
7.4.330.0000.00515.07
7.4.320.0000.00616.42
7.4.300.0000.00616.61
7.4.290.0030.00316.52
7.4.280.0060.00016.49
7.4.270.0060.00016.42
7.4.260.0030.00316.54
7.4.250.0060.00316.45
7.4.240.0030.00516.52
7.4.230.0070.00016.34
7.4.220.0080.00816.54
7.4.210.0030.01116.60
7.4.200.0000.00716.66
7.4.190.0040.00416.31
7.4.160.0130.00316.34
7.4.150.0070.01017.40
7.4.140.0120.00517.86
7.4.130.0090.00916.56
7.4.120.0100.01016.55
7.4.110.0140.00516.45
7.4.100.0090.00916.52
7.4.90.0070.01016.54
7.4.80.0200.00319.39
7.4.70.0130.00316.64
7.4.60.0130.00316.44
7.4.50.0000.00816.52
7.4.40.0060.00522.77
7.4.30.0070.01016.48
7.4.00.0040.00915.16
7.3.330.0000.00513.19
7.3.320.0020.00213.32
7.3.310.0050.00316.38
7.3.300.0000.00716.30
7.3.290.0040.01116.35
7.3.280.0070.00916.35
7.3.270.0090.00617.40
7.3.260.0030.01316.73
7.3.250.0080.00816.62
7.3.240.0040.01416.63
7.3.230.0150.00816.43
7.3.210.0070.01016.41
7.3.200.0100.00716.43
7.3.190.0190.00316.54
7.3.180.0060.01616.32
7.3.170.0030.01316.34
7.3.160.0040.01216.61
7.3.120.0030.00515.08
7.3.10.0060.01416.05
7.3.00.0130.00916.02
7.2.330.0110.00716.77
7.2.320.0100.00616.57
7.2.310.0100.00616.74
7.2.300.0070.01416.54
7.2.290.0080.00816.60
7.2.130.0280.00416.40
7.2.120.0180.00716.57
7.2.110.0080.00416.66
7.2.100.0120.00616.69
7.2.90.0120.00916.69
7.2.80.0070.00916.65
7.2.70.0060.00916.51
7.2.60.0150.00616.68
7.2.50.0070.00716.80
7.2.40.0080.01116.47
7.2.30.0150.01216.96
7.2.20.0110.00816.52
7.2.10.0130.00716.73
7.2.00.0070.01118.22
7.1.250.0190.00815.34
7.1.200.0080.00415.97
7.1.100.0000.01517.95
7.1.70.0000.00817.38
7.1.60.0060.00619.82
7.1.50.0030.01316.94
7.1.00.0030.07322.31
7.0.200.0000.00816.73
7.0.140.0100.06721.95
7.0.60.0070.08019.94
7.0.50.0130.07717.85
7.0.40.0070.07320.02
7.0.30.0230.08320.09
7.0.20.0230.04020.23
7.0.10.0230.04020.20
7.0.00.0170.06720.05
5.6.280.0030.07321.07
5.6.210.0130.03020.73
5.6.200.0100.08018.29
5.6.190.0000.05020.47
5.6.180.0230.08320.60
5.6.170.0200.04020.58
5.6.160.0130.07720.57
5.6.150.0030.04318.29
5.6.140.0070.04018.19
5.6.130.0130.07318.27
5.6.120.0100.07721.14
5.6.110.0170.07320.99
5.6.100.0100.08720.98
5.6.90.0130.08021.02
5.6.80.0100.08020.44
5.6.70.0330.07020.37
5.5.350.0230.08720.53
5.5.340.0000.04318.09
5.5.330.0070.03720.34
5.5.320.0170.06020.36
5.5.310.0300.05320.30
5.5.300.0070.08017.95
5.5.290.0030.04018.03
5.5.280.0100.05720.65
5.5.270.0070.04020.87
5.5.260.0070.08020.84
5.5.250.0130.07320.71
5.5.240.0030.04720.07
5.4.450.0100.07719.59
5.4.440.0330.05319.63
5.4.430.0230.05319.62
5.4.420.0200.06719.52
5.4.410.0170.07319.06
5.4.400.0830.00018.73
5.4.390.0770.00018.60
5.4.380.0270.05318.78
5.4.370.0200.05718.74
5.4.360.0430.04318.72
5.4.350.0230.06018.78
5.4.340.0370.04718.80
5.4.320.0050.03712.50
5.4.310.0060.03812.50
5.4.300.0050.03812.50
5.4.290.0060.04212.50
5.4.280.0060.04012.40
5.4.270.0060.03412.40
5.4.260.0200.05018.84
5.4.250.0170.06718.82
5.4.240.0070.06018.88
5.4.230.0000.05718.74
5.4.220.0070.05318.75
5.4.210.0100.05018.95
5.4.200.0030.06018.72
5.4.190.0100.05318.76
5.4.180.0100.05018.73
5.4.170.0070.06018.81
5.4.160.0070.05718.81
5.4.150.0130.05318.82
5.4.140.0100.05316.35
5.4.130.0130.04316.57
5.4.120.0030.05016.43
5.4.110.0030.05716.50
5.4.100.0000.07716.36
5.4.90.0030.05716.32
5.4.80.0030.06016.42
5.4.70.0170.06316.36
5.4.60.0070.07016.59
5.4.50.0130.05316.31
5.4.40.0130.05016.52
5.4.30.0100.05016.46
5.4.20.0070.04716.33
5.4.10.0030.06316.51
5.4.00.0070.06715.82
5.3.290.0070.04212.80
5.3.280.0100.05714.68
5.3.270.0070.05314.59
5.3.260.0070.06014.68
5.3.250.0100.05014.57
5.3.240.0030.05314.44
5.3.230.0030.05314.64
5.3.220.0030.07714.74
5.3.210.0100.06014.57
5.3.200.0100.05014.64
5.3.190.0070.05314.57
5.3.180.0030.06014.39
5.3.170.0070.05714.61
5.3.160.0030.05314.69
5.3.150.0170.06014.63
5.3.140.0130.06714.38
5.3.130.0030.06014.56
5.3.120.0100.07314.62
5.3.110.0070.05314.73
5.3.100.0130.05014.02
5.3.90.0130.05013.85
5.3.80.0030.07314.02
5.3.70.0100.06714.01
5.3.60.0070.06014.16
5.3.50.0130.06013.95
5.3.40.0030.05314.17
5.3.30.0070.05313.99
5.3.20.0070.04713.68
5.3.10.0000.06713.48
5.3.00.0070.05013.71
5.2.170.0070.04311.04
5.2.160.0070.04711.33
5.2.150.0030.04711.21
5.2.140.0030.04311.14
5.2.130.0070.04011.26
5.2.120.0070.03711.08
5.2.110.0000.04711.17
5.2.100.0070.03711.09
5.2.90.0070.03710.92
5.2.80.0070.04011.27
5.2.70.0030.04711.17
5.2.60.0000.05311.06
5.2.50.0130.05011.01
5.2.40.0030.04011.22
5.2.30.0030.04310.97
5.2.20.0070.03711.11
5.2.10.0000.04310.86
5.2.00.0100.04310.91
5.1.60.0070.05010.05
5.1.50.0100.0339.96
5.1.40.0100.0409.94
5.1.30.0030.03710.32
5.1.20.0030.03710.43
5.1.10.0030.03710.13
5.1.00.0030.05010.16
5.0.50.0070.0278.51
5.0.40.0070.0338.37
5.0.30.0030.0538.20
5.0.20.0070.0338.17
5.0.10.0030.0278.15
5.0.00.0030.0408.16
4.4.90.0030.0206.92
4.4.80.0070.0176.92
4.4.70.0030.0206.92
4.4.60.0030.0276.92
4.4.50.0030.0206.92
4.4.40.0030.0336.92
4.4.30.0030.0276.92
4.4.20.0000.0336.92
4.4.10.0000.0276.92
4.4.00.0100.0406.92
4.3.110.0030.0236.92
4.3.100.0030.0276.92
4.3.90.0000.0206.92
4.3.80.0030.0477.05
4.3.70.0070.0237.05
4.3.60.0070.0177.05
4.3.50.0030.0207.05
4.3.40.0030.0337.05
4.3.30.0000.0307.05
4.3.20.0030.0207.05
4.3.10.0030.0207.05
4.3.00.0100.0236.83

preferences:
46.85 ms | 401 KiB | 5 Q