3v4l.org

run code in 300+ PHP versions simultaneously
<?php function money_round ($amount) { # convert to string $string = (string)$amount; ## find out if negative ## if (substr($string, 0, 1) == '-') { $negative = true; $string = substr($string, 1, strlen($string) - 1); } else { $negative = false; } # if there's no decimal point add one on the end if (substr_count($string, '.') == 0) { $string .= '.'; } # add a few trailing '0's in case there aren't enough there already $string .= '000'; # find the decimal point $dotpos = strpos($string, '.'); # separate pounds $pounds = substr($string, 0, $dotpos); # separate pence $pence = substr($string, $dotpos + 1, 2); # find out how many tenths of a penny $tenths = substr($string, $dotpos + 3, 1); if ($tenths >= 5) { $pence++; if ($pence == 100) { $pence = '0'; $pounds++; } if ($pence < 10) { $pence = '0' . $pence; } } if ($negative) { return '-' . $pounds . '.' . $pence; } else { return $pounds . '.' . $pence; } } echo money_round(33333.333333333);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Qbkor
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   53     0  E >   INIT_FCALL                                               'money_round'
          1        SEND_VAL                                                 33333.3
          2        DO_FCALL                                      0  $0      
          3        ECHO                                                     $0
          4      > RETURN                                                   1

Function money_round:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 20
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 56, Position 2 = 65
Branch analysis from position: 56
2 jumps found. (Code = 43) Position 1 = 59, Position 2 = 61
Branch analysis from position: 59
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 65
Branch analysis from position: 63
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 71
Branch analysis from position: 66
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
Branch analysis from position: 61
Branch analysis from position: 65
Branch analysis from position: 28
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 28
Branch analysis from position: 27
Branch analysis from position: 28
filename:       /in/Qbkor
function name:  money_round
number of ops:  75
compiled vars:  !0 = $amount, !1 = $string, !2 = $negative, !3 = $dotpos, !4 = $pounds, !5 = $pence, !6 = $tenths
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    6     1        CAST                                          6  ~7      !0
          2        ASSIGN                                                   !1, ~7
    9     3        INIT_FCALL                                               'substr'
          4        SEND_VAR                                                 !1
          5        SEND_VAL                                                 0
          6        SEND_VAL                                                 1
          7        DO_ICALL                                         $9      
          8        IS_EQUAL                                                 $9, '-'
          9      > JMPZ                                                     ~10, ->20
   10    10    >   ASSIGN                                                   !2, <true>
   11    11        INIT_FCALL                                               'substr'
         12        SEND_VAR                                                 !1
         13        SEND_VAL                                                 1
         14        STRLEN                                           ~12     !1
         15        SUB                                              ~13     ~12, 1
         16        SEND_VAL                                                 ~13
         17        DO_ICALL                                         $14     
         18        ASSIGN                                                   !1, $14
         19      > JMP                                                      ->21
   13    20    >   ASSIGN                                                   !2, <false>
   17    21    >   INIT_FCALL                                               'substr_count'
         22        SEND_VAR                                                 !1
         23        SEND_VAL                                                 '.'
         24        DO_ICALL                                         $17     
         25        IS_EQUAL                                                 $17, 0
         26      > JMPZ                                                     ~18, ->28
   18    27    >   ASSIGN_OP                                     8          !1, '.'
   22    28    >   ASSIGN_OP                                     8          !1, '000'
   25    29        INIT_FCALL                                               'strpos'
         30        SEND_VAR                                                 !1
         31        SEND_VAL                                                 '.'
         32        DO_ICALL                                         $21     
         33        ASSIGN                                                   !3, $21
   28    34        INIT_FCALL                                               'substr'
         35        SEND_VAR                                                 !1
         36        SEND_VAL                                                 0
         37        SEND_VAR                                                 !3
         38        DO_ICALL                                         $23     
         39        ASSIGN                                                   !4, $23
   31    40        INIT_FCALL                                               'substr'
         41        SEND_VAR                                                 !1
         42        ADD                                              ~25     !3, 1
         43        SEND_VAL                                                 ~25
         44        SEND_VAL                                                 2
         45        DO_ICALL                                         $26     
         46        ASSIGN                                                   !5, $26
   34    47        INIT_FCALL                                               'substr'
         48        SEND_VAR                                                 !1
         49        ADD                                              ~28     !3, 3
         50        SEND_VAL                                                 ~28
         51        SEND_VAL                                                 1
         52        DO_ICALL                                         $29     
         53        ASSIGN                                                   !6, $29
   35    54        IS_SMALLER_OR_EQUAL                                      5, !6
         55      > JMPZ                                                     ~31, ->65
   36    56    >   PRE_INC                                                  !5
   37    57        IS_EQUAL                                                 !5, 100
         58      > JMPZ                                                     ~33, ->61
   38    59    >   ASSIGN                                                   !5, '0'
   39    60        PRE_INC                                                  !4
   41    61    >   IS_SMALLER                                               !5, 10
         62      > JMPZ                                                     ~36, ->65
   42    63    >   CONCAT                                           ~37     '0', !5
         64        ASSIGN                                                   !5, ~37
   46    65    > > JMPZ                                                     !2, ->71
   47    66    >   CONCAT                                           ~39     '-', !4
         67        CONCAT                                           ~40     ~39, '.'
         68        CONCAT                                           ~41     ~40, !5
         69      > RETURN                                                   ~41
         70*       JMP                                                      ->74
   49    71    >   CONCAT                                           ~42     !4, '.'
         72        CONCAT                                           ~43     ~42, !5
         73      > RETURN                                                   ~43
   51    74*     > RETURN                                                   null

End of function money_round

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.84 ms | 1411 KiB | 20 Q