3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getClosestIdByAmount($amount = 1){ $prices = array( array('id' => '28','price' =>100 ), array('id' => '29','price' =>105 ), array('id' => '30','price' =>110 ), array('id' => '31','price' =>115 ), array('id' => '32','price' =>120 ), array('id' => '33','price' =>125 ), array('id' => '34','price' =>130 ) ); $result_id = null; $take_next = false; foreach ($prices as $i => $item) { // amount < any price of the array if ($i === 0 && $item['price'] > $amount){ $result_id = $item['id']; break; } else { if ($item['price'] < $amount) { // amount > price1 AND amount < price2 $take_next = true; } elseif ($item['price'] == $amount){ // amount == some price $result_id = $item['id']; break; } else { if ($take_next){ $result_id = $item['id']; } break; } } } return "Amount: " . $amount . " Closest ID: " . $result_id . PHP_EOL; } $amount = 99; echo getClosestIdByAmount($amount); $amount = 113; echo getClosestIdByAmount($amount); $amount = 115; echo getClosestIdByAmount($amount); $amount = 131; echo getClosestIdByAmount($amount);

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.5.00.0130.00920.02
8.4.150.0020.00114.05
8.4.140.0120.00917.89
8.4.130.0110.01017.92
8.4.120.0110.00822.23
8.4.110.0120.00822.25
8.4.100.0120.00917.88
8.4.90.0130.00517.64
8.4.80.0090.00317.79
8.4.70.0110.00917.91
8.4.60.0120.00819.63
8.4.50.0100.01019.52
8.4.40.0090.00019.37
8.4.30.0100.01018.91
8.4.20.0120.00817.85
8.4.10.0030.00624.01
8.3.280.0140.00618.39
8.3.270.0100.00916.57
8.3.260.0110.00816.43
8.3.250.0050.00418.91
8.3.240.0120.00817.13
8.3.230.0100.00816.57
8.3.220.0130.00716.56
8.3.210.0080.01216.73
8.3.200.0100.00916.56
8.3.190.0100.00716.60
8.3.180.0090.00916.51
8.3.170.0040.00420.84
8.3.160.0100.00016.65
8.3.150.0080.00017.16
8.3.140.0050.00320.89
8.3.130.0040.00418.42
8.3.120.0060.00320.84
8.3.110.0090.00020.94
8.3.100.0000.01124.06
8.3.90.0080.00026.77
8.3.80.0000.00917.97
8.3.70.0110.00418.18
8.3.60.0140.00416.75
8.3.50.0120.00916.66
8.3.40.0070.00721.59
8.3.30.0030.01418.66
8.3.20.0040.00424.18
8.3.10.0070.00024.66
8.3.00.0080.00026.16
8.2.290.0130.00718.95
8.2.280.0110.00816.70
8.2.270.0030.00516.82
8.2.260.0090.00018.93
8.2.250.0060.00316.68
8.2.240.0060.00317.37
8.2.230.0040.00422.58
8.2.220.0080.00337.54
8.2.210.0030.00626.77
8.2.200.0060.00318.16
8.2.190.0130.01016.58
8.2.180.0160.00018.20
8.2.170.0040.01118.96
8.2.160.0070.00722.96
8.2.150.0040.00425.66
8.2.140.0000.00724.66
8.2.130.0040.00426.16
8.2.120.0090.00020.46
8.2.110.0060.00322.29
8.2.100.0040.00817.84
8.2.90.0080.00017.75
8.2.80.0000.00818.93
8.2.70.0060.00317.50
8.2.60.0030.00517.75
8.2.50.0000.00817.63
8.2.40.0130.00317.72
8.2.30.0160.00017.72
8.2.20.0110.00617.72
8.2.10.0080.00817.75
8.2.00.0130.00317.72
8.1.330.0110.00722.27
8.1.320.0110.00818.08
8.1.310.0150.00616.78
8.1.300.0040.00418.26
8.1.290.0040.00430.84
8.1.280.0080.00825.92
8.1.270.0040.00421.97
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0030.00623.98
8.1.230.0000.01119.07
8.1.220.0000.00817.77
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0000.00817.23
8.1.180.0000.00918.10
8.1.170.0110.00617.72
8.1.160.0130.00317.72
8.1.150.0170.00017.72
8.1.140.0110.00517.72
8.1.130.0040.01217.72
8.1.120.0000.01617.72
8.1.110.0080.00817.72
8.1.100.0120.00417.72
8.1.90.0120.00417.72
8.1.80.0100.00617.72
8.1.70.0080.00817.72
8.1.60.0090.00917.72
8.1.50.0100.00817.72
8.1.40.0070.01017.72
8.1.30.0140.00317.72
8.1.20.0190.00517.72
8.1.10.0130.00417.72
8.1.00.0130.00317.72
8.0.300.0000.00818.77
8.0.290.0040.00416.88
8.0.280.0130.00317.72
8.0.270.0120.00317.72
8.0.260.0070.01017.72
8.0.250.0110.00717.72
8.0.240.0150.00317.72
8.0.230.0120.00417.72
8.0.220.0100.00717.72
8.0.210.0100.00617.72
8.0.200.0160.00017.72
8.0.190.0170.00017.72
8.0.180.0130.00317.72
8.0.170.0120.00417.72
8.0.160.0110.00517.72
8.0.150.0140.00317.72
8.0.140.0080.00817.72
8.0.130.0100.00517.72
8.0.120.0100.00617.72
8.0.110.0160.00017.72
8.0.100.0100.00517.72
8.0.90.0130.00317.72
8.0.80.0160.00017.72
8.0.70.0160.00017.72
8.0.60.0080.00817.72
8.0.50.0130.00317.72
8.0.30.0060.00917.72
8.0.20.0120.00417.72
8.0.10.0130.00317.72

preferences:
29.48 ms | 403 KiB | 5 Q