3v4l.org

run code in 300+ PHP versions simultaneously
<?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"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 62
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 62
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
filename:       /in/rHujo
function name:  (null)
number of ops:  64
compiled vars:  !0 = $b, !1 = $cases, !2 = $caseItem, !3 = $caseKey, !4 = $calculatedUsage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 0
   20     1        ASSIGN                                                   !1, <array>
   29     2      > FE_RESET_R                                       $7      !1, ->62
          3    > > FE_FETCH_R                                       ~8      $7, !2, ->62
          4    >   ASSIGN                                                   !3, ~8
   30     5        CONCAT                                           ~10     'CASE+', !3
          6        CONCAT                                           ~11     ~10, '%3A+'
          7        FETCH_DIM_R                                      ~12     !2, 'price'
          8        CONCAT                                           ~13     ~11, ~12
          9        CONCAT                                           ~14     ~13, '+EUR'
         10        CONCAT                                           ~15     ~14, '%0A'
         11        ECHO                                                     ~15
   31    12        FETCH_DIM_R                                      ~16     !2, 'gas'
         13        CONCAT                                           ~17     'actual+gas%3A+', ~16
         14        CONCAT                                           ~18     ~17, '+m3'
         15        CONCAT                                           ~19     ~18, '%0A'
         16        ECHO                                                     ~19
   32    17        FETCH_DIM_R                                      ~20     !2, 'electricity'
         18        CONCAT                                           ~21     'actual+electricity%3A+', ~20
         19        CONCAT                                           ~22     ~21, '+kWh'
         20        CONCAT                                           ~23     ~22, '%0A'
         21        ECHO                                                     ~23
   34    22        INIT_FCALL                                               'getusage'
         23        FETCH_DIM_R                                      ~24     !2, 'price'
         24        SEND_VAL                                                 ~24
         25        DO_FCALL                                      0  $25     
         26        ASSIGN                                                   !4, $25
   36    27        FETCH_DIM_R                                      ~27     !4, 'gas'
         28        CONCAT                                           ~28     'calculated+gas%3A+', ~27
         29        CONCAT                                           ~29     ~28, '+m3'
         30        CONCAT                                           ~30     ~29, '%0A'
         31        ECHO                                                     ~30
   37    32        FETCH_DIM_R                                      ~31     !4, 'electricity'
         33        CONCAT                                           ~32     'calculated+electricity%3A+', ~31
         34        CONCAT                                           ~33     ~32, '+kWh'
         35        CONCAT                                           ~34     ~33, '%0A%0A'
         36        ECHO                                                     ~34
   39    37        INIT_FCALL                                               'round'
         38        FETCH_DIM_R                                      ~35     !4, 'gas'
         39        FETCH_DIM_R                                      ~36     !2, 'gas'
         40        DIV                                              ~37     ~35, ~36
         41        MUL                                              ~38     ~37, 100
         42        SEND_VAL                                                 ~38
         43        SEND_VAL                                                 2
         44        DO_ICALL                                         $39     
         45        CONCAT                                           ~40     'gas+relative+to+actual%3A+', $39
         46        CONCAT                                           ~41     ~40, '+%25'
         47        CONCAT                                           ~42     ~41, '%0A'
         48        ECHO                                                     ~42
   40    49        INIT_FCALL                                               'round'
         50        FETCH_DIM_R                                      ~43     !4, 'electricity'
         51        FETCH_DIM_R                                      ~44     !2, 'electricity'
         52        DIV                                              ~45     ~43, ~44
         53        MUL                                              ~46     ~45, 100
         54        SEND_VAL                                                 ~46
         55        SEND_VAL                                                 2
         56        DO_ICALL                                         $47     
         57        CONCAT                                           ~48     'electricity+relative+to+actual%3A+', $47
         58        CONCAT                                           ~49     ~48, '+%25'
         59        CONCAT                                           ~50     ~49, '%0A%0A%0A'
         60        ECHO                                                     ~50
   29    61      > JMP                                                      ->3
         62    >   FE_FREE                                                  $7
   41    63      > RETURN                                                   1

Function getusage:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rHujo
function name:  getUsage
number of ops:  35
compiled vars:  !0 = $b, !1 = $f, !2 = $usageElectricityStart, !3 = $gas, !4 = $electricity
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    6     1        DIV                                              ~5      !0, 100000
          2        ADD                                              ~6      0.0335, ~5
          3        ASSIGN                                                   !1, ~6
    8     4        IS_SMALLER                                               100, !0
          5      > JMPZ                                                     ~8, ->8
    9     6    >   ASSIGN                                                   !2, 750
          7      > JMP                                                      ->13
   11     8    >   INIT_FCALL                                               'round'
          9        MUL                                              ~10     !0, 7.5
         10        SEND_VAL                                                 ~10
         11        DO_ICALL                                         $11     
         12        ASSIGN                                                   !2, $11
   14    13    >   INIT_FCALL                                               'round'
         14        DIV                                              ~13     !0, !1
         15        MUL                                              ~14     !0, 4
         16        DIV                                              ~15     ~14, 10000
         17        ADD                                              ~16     0.25, ~15
         18        MUL                                              ~17     ~13, ~16
         19        SEND_VAL                                                 ~17
         20        SEND_VAL                                                 -1
         21        DO_ICALL                                         $18     
         22        ASSIGN                                                   !3, $18
   15    23        INIT_FCALL                                               'round'
         24        DIV                                              ~20     !0, !1
         25        MUL                                              ~21     ~20, 0.625
         26        ADD                                              ~22     !2, ~21
         27        SEND_VAL                                                 ~22
         28        SEND_VAL                                                 -1
         29        DO_ICALL                                         $23     
         30        ASSIGN                                                   !4, $23
   17    31        INIT_ARRAY                                       ~25     !3, 'gas'
         32        ADD_ARRAY_ELEMENT                                ~25     !4, 'electricity'
         33      > RETURN                                                   ~25
   18    34*     > RETURN                                                   null

End of function getusage

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.7 ms | 1407 KiB | 16 Q