3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $b = 0; function getUsage($b) { $f = 0.0335 + ($b / 100000); if ($b > 100) { $usageElectricityStart = 750; } else { $usageElectricityStart = round($b * 7.5); } $gas = round($b / $f * (0.25 + (4 * $b / 10000)), -1); $electricity = round($usageElectricityStart + $b / $f * 0.625, -1); return array('gas' => $gas, 'electricity' => $electricity); } $cases = array( 1 => array('price' => 294, 'gas' => 2887, 'electricity' => 5789), 2 => array('price' => 137, 'gas' => 1527, 'electricity' => 2620), 3 => array('price' => 127, 'gas' => 750, 'electricity' => 3650), 4 => array('price' => 139, 'gas' => 1227, 'electricity' => 3201), 5 => array('price' => 230, 'gas' => 2555, 'electricity' => 4317), 6 => array('price' => 79, 'gas' => 544, 'electricity' => 2339) ); foreach ($cases as $caseKey => $caseItem) { echo 'CASE ' . $caseKey . ': ' . $caseItem['price'] .' EUR' . "\n"; echo 'actual gas: ' . $caseItem['gas'] . ' m3' . "\n"; echo 'actual electricity: ' . $caseItem['electricity'] . ' kWh' . "\n"; $calculatedUsage = getUsage($caseItem['price']); echo 'calculated gas: ' . $calculatedUsage['gas'] . ' m3' . "\n"; echo 'calculated electricity: ' . $calculatedUsage['electricity'] . ' kWh' . "\n\n"; echo 'gas relative to actual: ' . round($calculatedUsage['gas'] / $caseItem['gas'] * 100, 2) . ' %' . "\n"; echo 'electricity relative to actual: ' . round($calculatedUsage['electricity'] / $caseItem['electricity'] * 100, 2) . ' %' . "\n\n\n"; }
based on 2UVND
Output for 5.6.0 - 7.3.0beta1
CASE 1: 294 EUR actual gas: 2887 m3 actual electricity: 5789 kWh calculated gas: 2970 m3 calculated electricity: 5790 kWh gas relative to actual: 102.87 % electricity relative to actual: 100.02 % CASE 2: 137 EUR actual gas: 1527 m3 actual electricity: 2620 kWh calculated gas: 1200 m3 calculated electricity: 3210 kWh gas relative to actual: 78.59 % electricity relative to actual: 122.52 % CASE 3: 127 EUR actual gas: 750 m3 actual electricity: 3650 kWh calculated gas: 1100 m3 calculated electricity: 3030 kWh gas relative to actual: 146.67 % electricity relative to actual: 83.01 % CASE 4: 139 EUR actual gas: 1227 m3 actual electricity: 3201 kWh calculated gas: 1220 m3 calculated electricity: 3240 kWh gas relative to actual: 99.43 % electricity relative to actual: 101.22 % CASE 5: 230 EUR actual gas: 2555 m3 actual electricity: 4317 kWh calculated gas: 2200 m3 calculated electricity: 4770 kWh gas relative to actual: 86.11 % electricity relative to actual: 110.49 % CASE 6: 79 EUR actual gas: 544 m3 actual electricity: 2339 kWh calculated gas: 650 m3 calculated electricity: 2030 kWh gas relative to actual: 119.49 % electricity relative to actual: 86.79 %