3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $input='46.99'; $floor=floor($input); $tens=round($input,-1); echo $floor.' '.$tens."\n"; function getClosest($search, $arr) { $closest = null; foreach($arr as $item) { if($closest == null || abs($search - $closest) > abs($item - $search)) { $closest = $item; } } return $closest; } function roundToValues( $search, array $arr ) { $differences = array(); foreach( $arr as $item) { $differences[ $item ] = abs($item - $search); } return array_search(min($differences), $differences); } $array = [ '0' => '0', '20' => '0-20', '50' => '20-50', '100' => '50-100', '200' => '100-200', '500' => '200-500', ]; print_r($array); echo getClosest($input,$array).' '.roundToValues($input,$array);
based on X9dfF

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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.2.60.0000.01416.78
7.2.00.0100.01019.32
7.1.200.0030.00915.92
7.1.100.0030.00717.76
7.1.70.0040.00417.19
7.1.60.0040.02219.25
7.1.50.0220.01634.84
7.1.00.0030.07722.54
7.0.200.0040.00416.71
7.0.140.0130.06322.04
7.0.60.0100.08019.99
7.0.50.0030.09017.88
7.0.40.0170.04320.27
7.0.30.0200.03720.17
7.0.20.0370.07020.05
7.0.10.0170.08020.06
7.0.00.0030.04320.15
5.6.280.0100.06721.07
5.6.210.0070.09020.72
5.6.200.0130.04718.19
5.6.190.0030.06020.39
5.6.180.3630.04720.58
5.6.170.0270.08720.48
5.6.160.0030.05020.50
5.6.150.0100.06018.29
5.6.140.0100.07718.18
5.6.130.0270.03018.20
5.6.120.0100.05320.99
5.6.110.0070.08721.02
5.6.100.0070.04020.98
5.6.90.0130.08720.97
5.6.80.0070.04020.41
5.6.70.4430.03720.25
5.5.350.0100.07320.39
5.5.340.0070.06717.98
5.5.330.0030.04320.42
5.5.320.3430.04020.30
5.5.310.0130.05020.48
5.5.300.0030.07017.98
5.5.290.0030.08317.99
5.5.280.0030.04020.90
5.5.270.0030.08720.80
5.5.260.0130.06020.87
5.5.250.0070.05720.63
5.5.240.0300.07320.37
5.4.450.0200.04719.18
5.4.440.0230.05019.38
5.4.430.0270.02719.47
5.4.420.0230.04319.16
5.4.410.0330.03719.36
5.4.400.0370.03319.09
5.4.390.0300.04019.22
5.4.380.0130.05318.54
5.4.370.0130.05718.53
5.4.360.0130.05318.76
5.4.350.0270.04318.59
5.4.340.0170.05018.75
5.4.320.0040.03812.52
5.4.310.0070.04412.52
5.4.300.0070.04612.51
5.4.290.0090.03712.51
5.4.280.0070.03912.41
5.4.270.0070.03812.41
5.4.260.0060.04112.41
5.4.250.0040.04212.41
5.4.240.0110.04712.41
5.4.230.0090.05612.40
5.4.220.0080.05912.41
5.4.210.0070.04912.40
5.4.200.0090.04912.40
5.4.190.0070.04012.39
5.4.180.0150.04812.40
5.4.170.0110.04912.41
5.4.160.0090.03912.40
5.4.150.0080.03912.39
5.4.140.0090.04312.08
5.4.130.0080.03812.07
5.4.120.0100.04812.02
5.4.110.0080.04112.02
5.4.100.0120.04212.02
5.4.90.0110.04112.02
5.4.80.0130.05012.02
5.4.70.0100.05312.02
5.4.60.0130.05212.02
5.4.50.0090.04712.02
5.4.40.0090.04512.00
5.4.30.0060.04412.00
5.4.20.0060.03712.00
5.4.10.0050.03812.00
5.4.00.0090.04311.49
5.3.290.0060.04112.80
5.3.280.0100.04712.71
5.3.270.0060.04312.72
5.3.260.0040.04212.72
5.3.250.0060.03812.72
5.3.240.0100.05212.72
5.3.230.0040.04812.71
5.3.220.0120.03712.68
5.3.210.0120.04912.68
5.3.200.0050.05312.68
5.3.190.0120.03612.68
5.3.180.0040.03912.67
5.3.170.0060.03712.67
5.3.160.0080.03512.67
5.3.150.0060.03812.67
5.3.140.0070.05412.66
5.3.130.0050.04212.66
5.3.120.0050.04012.66
5.3.110.0060.04112.66
5.3.100.0070.03612.13
5.3.90.0050.03812.11
5.3.80.0030.04012.10
5.3.70.0090.04412.10
5.3.60.0070.03812.09
5.3.50.0040.04012.03
5.3.40.0030.04512.04
5.3.30.0130.04111.99
5.3.20.0090.03511.79
5.3.10.0030.04011.74
5.3.00.0030.03911.73
5.2.170.0050.0319.22
5.2.160.0060.0319.23
5.2.150.0070.0299.23
5.2.140.0060.0319.23
5.2.130.0070.0279.19
5.2.120.0030.0319.18
5.2.110.0080.0409.19
5.2.100.0030.0349.18
5.2.90.0030.0329.19
5.2.80.0100.0319.18
5.2.70.0050.0319.18
5.2.60.0070.0349.14
5.2.50.0070.0309.11
5.2.40.0060.0299.09
5.2.30.0070.0339.05
5.2.20.0030.0339.05
5.2.10.0110.0288.95
5.2.00.0040.0368.82
5.1.60.0070.0298.10
5.1.50.0120.0368.10
5.1.40.0120.0318.08
5.1.30.0080.0338.43
5.1.20.0050.0298.45
5.1.10.0070.0268.18
5.1.00.0060.0278.18
5.0.50.0060.0286.66
5.0.40.0050.0226.52
5.0.30.0040.0406.32
5.0.20.0030.0206.29
5.0.10.0070.0216.27
5.0.00.0030.0326.26
4.4.90.0020.0174.78
4.4.80.0040.0194.76
4.4.70.0050.0214.75
4.4.60.0040.0234.76
4.4.50.0020.0184.77
4.4.40.0040.0264.71
4.4.30.0030.0184.76
4.4.20.0050.0334.85
4.4.10.0040.0224.85
4.4.00.0040.0284.76
4.3.110.0060.0204.67
4.3.100.0030.0174.66
4.3.90.0040.0224.64
4.3.80.0030.0334.58
4.3.70.0030.0164.63
4.3.60.0030.0154.63
4.3.50.0040.0154.63
4.3.40.0050.0224.54
4.3.30.0040.0143.32
4.3.20.0030.0153.29
4.3.10.0040.0163.25
4.3.00.0030.01315.26