3v4l.org

run code in 300+ PHP versions simultaneously
<?php private 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 = "1970"; 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)
5.4.260.0230.04718.99
5.4.250.0300.06719.13
5.4.240.0200.06019.20
5.4.230.0200.06019.08
5.4.220.0300.04719.13
5.4.210.0370.04019.21
5.4.200.0200.05018.94
5.4.190.0200.07319.21
5.4.180.0230.07018.98
5.4.170.0200.07019.07
5.4.160.0170.04019.13
5.4.150.0230.03018.84
5.4.140.0200.07016.35
5.4.130.0130.04716.33
5.4.120.0170.05316.30
5.4.110.0200.03316.45
5.4.100.0200.07016.56
5.4.90.0230.05016.27
5.4.80.0170.03716.55
5.4.70.0200.04016.40
5.4.60.0170.05716.53
5.4.50.0200.04716.33
5.4.40.0270.06316.42
5.4.30.0300.05716.53
5.4.20.0300.05316.23
5.4.10.0130.04016.23
5.4.00.0270.06315.76
5.3.280.0230.05014.53
5.3.270.0300.06014.48
5.3.260.0270.03714.46
5.3.250.0200.03714.56
5.3.240.0230.07314.46
5.3.230.0200.07714.68
5.3.220.0200.07714.60
5.3.210.0200.03714.40
5.3.200.0270.07014.45
5.3.190.0300.06314.40
5.3.180.0170.04714.56
5.3.170.0270.06314.59
5.3.160.0230.04714.63
5.3.150.0200.07014.44
5.3.140.0230.06014.51
5.3.130.0270.06714.39
5.3.120.0230.06014.40
5.3.110.0170.05314.39
5.3.100.0200.06713.88
5.3.90.0130.08013.88
5.3.80.0200.07013.89
5.3.70.0170.04313.83
5.3.60.0300.05013.98
5.3.50.0270.03013.89
5.3.40.0230.07013.77
5.3.30.0270.06713.79
5.3.20.0230.05013.78
5.3.10.0200.05713.70
5.3.00.0200.03313.51
5.2.170.0100.04311.96
5.2.160.0200.05311.96
5.2.150.0170.05311.96
5.2.140.0200.05011.96
5.2.130.0230.05711.96
5.2.120.0130.04711.96
5.2.110.0100.03711.96
5.2.100.0130.03011.96
5.2.90.0130.03011.96
5.2.80.0300.04311.96
5.2.70.0170.03011.96
5.2.60.0200.04011.96
5.2.50.0170.04011.96
5.2.40.0130.03011.96
5.2.30.0230.05311.96
5.2.20.0170.05711.96
5.2.10.0170.03711.96
5.2.00.0100.03711.96
5.1.60.0130.02311.96
5.1.50.0030.04011.96
5.1.40.0130.02711.96
5.1.30.0200.05311.96
5.1.20.0130.03311.96
5.1.10.0200.02711.96
5.1.00.0070.02711.96
5.0.50.0030.02311.96
5.0.40.0030.03311.96
5.0.30.0100.05011.96
5.0.20.0100.04311.96
5.0.10.0100.04311.96
5.0.00.0100.05011.96
4.4.90.0070.01711.96
4.4.80.0130.02311.96
4.4.70.0100.03311.96
4.4.60.0070.02711.96
4.4.50.0070.02711.96
4.4.40.0030.02711.96
4.4.30.0070.03311.96
4.4.20.0030.02011.96
4.4.10.0030.01711.96
4.4.00.0030.02711.96
4.3.110.0030.02311.96
4.3.100.0070.03711.96
4.3.90.0070.02311.96
4.3.80.0100.05011.96
4.3.70.0130.03011.96
4.3.60.0070.01711.96
4.3.50.0130.01311.96
4.3.40.0070.04711.96
4.3.30.0070.02711.96
4.3.20.0070.03011.96
4.3.10.0030.02011.96
4.3.00.0030.01311.96

preferences:
139.18 ms | 1394 KiB | 7 Q