3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ ['threshold' => 3000, 'value' => 216], ['threshold' => 4000, 'value' => 254], ['threshold' => 5000, 'value' => 292], ['threshold' => 6000, 'value' => 330], ['threshold' => 7000, 'value' => 368], ['threshold' => 8000, 'value' => 406], ['threshold' => 9000, 'value' => 444], ['threshold' => 10000, 'value' => 482], ['threshold' => 13000, 'value' => 534], ['threshold' => 16000, 'value' => 586], ['threshold' => 19000, 'value' => 638], ['threshold' => 22000, 'value' => 690], ['threshold' => 25000, 'value' => 742], ['threshold' => 30000, 'value' => 812], ['threshold' => 35000, 'value' => 882], ['threshold' => 40000, 'value' => 952], ['threshold' => 45000, 'value' => 1022], ['threshold' => 50000, 'value' => 1092], ['threshold' => 65000, 'value' => 1332], ['threshold' => 80000, 'value' => 1572], ['threshold' => 95000, 'value' => 1812], ['threshold' => 110000, 'value' => 2052], ['threshold' => 125000, 'value' => 2292], ['threshold' => 140000, 'value' => 2532], ['threshold' => 155000, 'value' => 2772], ['threshold' => 170000, 'value' => 3012], ['threshold' => 185000, 'value' => 3252], ['threshold' => 200000, 'value' => 3492], ['threshold' => 230000, 'value' => 3850], ['threshold' => 260000, 'value' => 4208], ['threshold' => 290000, 'value' => 4566], ['threshold' => 320000, 'value' => 4924], ['threshold' => 350000, 'value' => 5282], ['threshold' => 380000, 'value' => 5640], ['threshold' => 410000, 'value' => 5998], ['threshold' => 440000, 'value' => 6356], ['threshold' => 470000, 'value' => 6714], ['threshold' => 500000, 'value' => 7072], ['threshold' => 550000, 'value' => 7432], ['threshold' => 600000, 'value' => 7792], ['threshold' => 650000, 'value' => 8152], ['threshold' => 700000, 'value' => 8512], ['threshold' => 750000, 'value' => 8872], ['threshold' => 800000, 'value' => 9232], ['threshold' => 850000, 'value' => 9592], ['threshold' => 900000, 'value' => 9952], ['threshold' => 950000, 'value' => 10312], ['threshold' => 1000000, 'value' => 10672] ]; function getClosest($search, $arr) { $closest = null; $i = 0; $index = 0; // Loop over the array and check if the currently closest value is higher than the current iteration foreach ($arr as $item) { if ($closest === null || abs($search - $closest['threshold']) > abs($item['threshold'] - $search)) { $closest = $item; $index = $i; } $i++; } $finalIndex = $index + 1; if($finalIndex >= count($arr)) { $finalIndex -= 1; } return floatval($arr[$finalIndex]['value']); } $result = getClosest(2500, $arr); echo $result;

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.0170.00316.63
8.3.50.0030.01316.48
8.3.40.0110.00418.63
8.3.30.0110.00418.63
8.3.20.0050.00321.85
8.3.10.0000.00721.73
8.3.00.0040.00418.80
8.2.180.0110.00418.43
8.2.170.0070.01122.96
8.2.160.0070.00722.17
8.2.150.0040.00424.18
8.2.140.0070.00024.66
8.2.130.0100.00020.16
8.2.120.0040.00426.35
8.2.110.0070.00319.16
8.2.100.0040.00717.97
8.2.90.0030.00519.35
8.2.80.0090.00017.97
8.2.70.0060.00317.63
8.2.60.0050.00318.05
8.2.50.0000.00818.10
8.2.40.0080.00020.42
8.2.30.0060.00319.31
8.2.20.0040.00418.19
8.2.10.0050.00218.00
8.2.00.0000.00718.19
8.1.280.0070.00725.92
8.1.270.0000.00823.91
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0030.00723.88
8.1.230.0090.00319.02
8.1.220.0050.00317.79
8.1.210.0090.00018.77
8.1.200.0070.00317.47
8.1.190.0030.00617.10
8.1.180.0030.00518.10
8.1.170.0040.00418.66
8.1.160.0060.00318.86
8.1.150.0040.00420.13
8.1.140.0000.00819.46
8.1.130.0000.00818.78
8.1.120.0030.00617.55
8.1.110.0020.00517.44
8.1.100.0000.00717.40
8.1.90.0050.00217.43
8.1.80.0040.00417.38
8.1.70.0000.00817.44
8.1.60.0020.00517.64
8.1.50.0030.00517.52
8.1.40.0080.00017.54
8.1.30.0000.00817.69
8.1.20.0080.00017.63
8.1.10.0040.00417.54
8.1.00.0030.00617.59
8.0.300.0000.00821.88
8.0.290.0060.00316.75
8.0.280.0000.00718.46
8.0.270.0030.00317.23
8.0.260.0000.00616.80
8.0.250.0030.00316.87
8.0.240.0030.00617.00
8.0.230.0060.00317.00
8.0.220.0030.00316.77
8.0.210.0070.00016.84
8.0.200.0040.00416.98
8.0.190.0040.00416.90
8.0.180.0050.00316.95
8.0.170.0000.00816.83
8.0.160.0000.00816.86
8.0.150.0030.00516.81
8.0.140.0000.00716.89
8.0.130.0030.00313.32
8.0.120.0000.00716.90
8.0.110.0030.00516.94
8.0.100.0000.00716.78
8.0.90.0000.00716.79
8.0.80.0080.00816.84
8.0.70.0040.00416.70
8.0.60.0040.00416.79
8.0.50.0050.00216.94
8.0.30.0110.00517.08
8.0.20.0120.00817.40
8.0.10.0050.00216.90
8.0.00.0110.00716.54
7.4.330.0050.00015.55
7.4.320.0030.00316.47
7.4.300.0030.00316.42
7.4.290.0050.00316.42
7.4.280.0040.00416.52
7.4.270.0000.00716.58
7.4.260.0060.00013.30
7.4.250.0040.00416.48
7.4.240.0030.00316.67
7.4.230.0070.00016.70
7.4.220.0130.00916.45
7.4.210.0100.00716.71
7.4.200.0040.00416.68
7.4.160.0120.00616.44
7.4.150.0090.00917.40
7.4.140.0100.00817.86
7.4.130.0100.01316.30
7.4.120.0120.00916.41
7.4.110.0100.00716.60
7.4.100.0030.01516.30
7.4.90.0120.00616.65
7.4.80.0180.00619.39
7.4.70.0030.01416.35
7.4.60.0130.00316.48
7.4.50.0140.00016.69
7.4.40.0100.00716.67
7.4.30.0040.01116.43
7.4.00.0060.01214.95
7.3.330.0030.00313.41
7.3.320.0000.00613.42
7.3.310.0080.00016.21
7.3.300.0020.00516.36
7.3.290.0060.00816.38
7.3.280.0080.00816.38
7.3.270.0090.00917.40
7.3.260.0140.00616.54
7.3.250.0080.01216.44
7.3.240.0120.00516.39
7.3.230.0100.00716.54
7.3.210.0060.01216.53
7.3.200.0160.00016.53
7.3.190.0140.00316.52
7.3.180.0120.00616.39
7.3.170.0060.01316.41
7.3.160.0120.00616.61
7.3.120.0100.01015.14
7.3.110.0070.00714.70
7.3.100.0030.01015.02
7.3.90.0080.00314.78
7.3.80.0030.01214.95
7.3.70.0090.00014.92
7.3.60.0090.00614.96
7.3.50.0030.01014.70
7.3.40.0100.00314.90
7.3.30.0000.01514.55
7.3.20.0030.01016.79
7.3.10.0070.00316.86
7.3.00.0030.01016.85
7.2.330.0100.00716.54
7.2.320.0070.01016.85
7.2.310.0120.00916.57
7.2.300.0130.00816.45
7.2.290.0160.00016.80
7.2.250.0090.00915.30
7.2.240.0110.00715.23
7.2.230.0040.01114.60
7.2.220.0060.00315.07
7.2.210.0090.00615.09
7.2.200.0000.01214.82
7.2.190.0000.01015.13
7.2.180.0130.00315.03
7.2.170.0000.01515.11
7.2.60.0070.00716.54
7.2.00.0040.00819.17
7.1.330.0070.00715.91
7.1.320.0070.00715.73
7.1.310.0080.00615.79
7.1.300.0060.01215.75
7.1.290.0080.00815.62
7.1.280.0060.00915.69
7.1.270.0040.01115.96
7.1.260.0050.00515.68
7.1.200.0090.00615.68
7.1.100.0030.00918.29
7.1.70.0080.00016.93
7.1.60.0400.01033.30
7.1.50.0600.01733.03
7.1.40.0600.01332.71
7.1.30.0470.02732.60
7.1.20.0430.01732.83
7.1.10.0370.00714.69
7.1.00.0270.01014.77
7.0.200.0400.01314.78
7.0.190.0370.01015.04
7.0.180.0470.01014.63
7.0.170.0400.01314.68
7.0.160.1070.01014.57
7.0.150.0300.01014.40
7.0.140.0300.00714.49
7.0.130.0330.00714.60
7.0.120.0430.01314.64
7.0.110.0400.01014.45
7.0.100.0200.01314.46
7.0.90.0400.01314.57
7.0.80.0400.01314.61
7.0.70.0270.01014.56
7.0.60.0330.00314.38
7.0.50.0170.01014.59
7.0.40.0030.01014.59
7.0.30.0270.01314.57
7.0.20.0330.01014.79
7.0.10.0430.01014.54
7.0.00.0370.01014.50

preferences:
60.39 ms | 401 KiB | 5 Q