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, 0); $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"; } ?>
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Method 1: Weight= 1 , Extra Weight: -20 Method 1: Weight= 1 , Extra Cost: -20 Method 2: Weight= 1 , Extra Weight: -20 Method 2: Weight= 1 , Extra Cost: -20 Method 1: Weight= 100 , Extra Weight: -20 Method 1: Weight= 100 , Extra Cost: -20 Method 2: Weight= 100 , Extra Weight: -20 Method 2: Weight= 100 , Extra Cost: -20 Method 1: Weight= 111 , Extra Weight: -20 Method 1: Weight= 111 , Extra Cost: -20 Method 2: Weight= 111 , Extra Weight: -20 Method 2: Weight= 111 , Extra Cost: -20 Method 1: Weight= 168 , Extra Weight: -20 Method 1: Weight= 168 , Extra Cost: -20 Method 2: Weight= 168 , Extra Weight: -20 Method 2: Weight= 168 , Extra Cost: -20 Method 1: Weight= 569 , Extra Weight: -19 Method 1: Weight= 569 , Extra Cost: -19 Method 2: Weight= 569 , Extra Weight: -19 Method 2: Weight= 569 , Extra Cost: -19 Method 1: Weight= 1652 , Extra Weight: -18 Method 1: Weight= 1652 , Extra Cost: -18 Method 2: Weight= 1652 , Extra Weight: -18 Method 2: Weight= 1652 , Extra Cost: -18 Method 1: Weight= 16549 , Extra Weight: -3 Method 1: Weight= 16549 , Extra Cost: -3 Method 2: Weight= 16549 , Extra Weight: -3 Method 2: Weight= 16549 , Extra Cost: -3 Method 1: Weight= 19999 , Extra Weight: -0 Method 1: Weight= 19999 , Extra Cost: -0 Method 2: Weight= 19999 , Extra Weight: -0 Method 2: Weight= 19999 , Extra Cost: -0 Method 1: Weight= 20000 , Extra Weight: 0 Method 1: Weight= 20000 , Extra Cost: 0 Method 2: Weight= 20000 , Extra Weight: 0 Method 2: Weight= 20000 , Extra Cost: 0 Method 1: Weight= 20001 , Extra Weight: 0 Method 1: Weight= 20001 , Extra Cost: 0 Method 2: Weight= 20001 , Extra Weight: 0 Method 2: Weight= 20001 , Extra Cost: 0 Method 1: Weight= 25649 , Extra Weight: 6 Method 1: Weight= 25649 , Extra Cost: 6 Method 2: Weight= 25649 , Extra Weight: 6 Method 2: Weight= 25649 , Extra Cost: 6 Method 1: Weight= 35216 , Extra Weight: 15 Method 1: Weight= 35216 , Extra Cost: 15 Method 2: Weight= 35216 , Extra Weight: 15 Method 2: Weight= 35216 , Extra Cost: 15 Method 1: Weight= 54961 , Extra Weight: 35 Method 1: Weight= 54961 , Extra Cost: 35 Method 2: Weight= 54961 , Extra Weight: 35 Method 2: Weight= 54961 , Extra Cost: 35
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/7Ho4b on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/7Ho4b on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/7Ho4b on line 3
Process exited with code 255.

preferences:
267.39 ms | 401 KiB | 341 Q