3v4l.org

run code in 300+ PHP versions simultaneously
<?php const THRESHOLD_PRICES = [ 2 => 8.23, 5 => 10.97, 10 => 13.28, 15 => 15.40, 20 => 18.15, 25 => 20.36, 30 => 22.84, 40 => 25.60, 50 => 28.35, 60 => 31.89, 70 => 36.23, 80 => 39.40, 90 => 42.52, 100 => 44.75 ]; function getThresholdPrice(int $search): float { if (isset(THRESHOLD_PRICES[$search])) { return THRESHOLD_PRICES[$search]; } foreach (THRESHOLD_PRICES as $threshold => $price) { if ($threshold > $search) { break; } } return $price; } foreach (range(1, 105, 13) as $test) { printf("%d => %.02f\n", $test, getThresholdPrice($test)); }

preferences:
23.53 ms | 405 KiB | 5 Q