3v4l.org

run code in 300+ PHP versions simultaneously
<?php $weights = [1, 100, 111, 168, 569, 1652, 16549, 19999, 20000, 20001, 25649, 35216, 54961]; foreach($weights as $index => $weight) { $extra_weight = round($weight-20000, 3)/1000; $extra_cost = $extra_weight * 1.00; echo "Method 1: Weight= $weight , Extra Weight: $extra_weight \n"; echo "Method 1: Weight= $weight , Extra Cost: $extra_weight \n"; $extra_weight = round((($weight-20000))/1000, -3); $extra_cost = $extra_weight * 1.00; echo "Method 2: Weight= $weight , Extra Weight: $extra_weight \n"; echo "Method 2: Weight= $weight , Extra Cost: $extra_weight \n"; } ?>

preferences:
39.28 ms | 402 KiB | 5 Q