3v4l.org

run code in 500+ PHP versions simultaneously
<?php function price_format($num,$type = 1){ $num_full = number_format((float)$num,2,'.',''); if (strpos($num, '.') !== false) { $num = substr($num_full, 0, strpos($num_full, ".")); } if($type == 1){ // '₹10,00,000.00/-' $explrestunits = "" ; if(strlen($num)>3) { $lastthree = substr($num, strlen($num)-3, strlen($num)); $restunits = substr($num, 0, strlen($num)-3); // extracts the last three digits $restunits = (strlen($restunits)%2 == 1)?"0".$restunits:$restunits; // explodes the remaining digits in 2's formats, adds a zero in the beginning to maintain the 2's grouping. $expunit = str_split($restunits, 2); for($i=0; $i<sizeof($expunit); $i++) { // creates each of the 2's group and adds a comma to the end if($i==0) { $explrestunits .= (int)$expunit[$i].","; // if is first value , convert into integer } else { $explrestunits .= $expunit[$i].","; } } $thecash = "₹".$explrestunits.$lastthree.substr($num_full, -3)."/-"; } else { $thecash = "₹".$num.substr($num_full, -3)."/-"; } return $thecash; // writes the final format where $currency is the currency symbol. } } echo price_format(1).PHP_EOL; echo price_format(10).PHP_EOL; echo price_format(84289.35);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cEQUI
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   32     0  E >   INIT_FCALL                                                   'price_format'
          1        SEND_VAL                                                     1
          2        DO_FCALL                                          0  $0      
          3        CONCAT                                               ~1      $0, '%0A'
          4        ECHO                                                         ~1
   33     5        INIT_FCALL                                                   'price_format'
          6        SEND_VAL                                                     10
          7        DO_FCALL                                          0  $2      
          8        CONCAT                                               ~3      $2, '%0A'
          9        ECHO                                                         ~3
   34    10        INIT_FCALL                                                   'price_format'
         11        SEND_VAL                                                     84289.4
         12        DO_FCALL                                          0  $4      
         13        ECHO                                                         $4
         14      > RETURN                                                       1

Function price_format:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 17
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 77
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 71
Branch analysis from position: 23
2 jumps found. (Code = 43) Position 1 = 38, Position 2 = 41
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 50
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 50
2 jumps found. (Code = 43) Position 1 = 52, Position 2 = 57
Branch analysis from position: 52
1 jumps found. (Code = 42) Position 1 = 60
Branch analysis from position: 60
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 50
Branch analysis from position: 64
Branch analysis from position: 50
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 50
Branch analysis from position: 64
Branch analysis from position: 50
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
Branch analysis from position: 71
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 77
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
filename:       /in/cEQUI
function name:  price_format
number of ops:  78
compiled vars:  !0 = $num, !1 = $type, !2 = $num_full, !3 = $explrestunits, !4 = $lastthree, !5 = $restunits, !6 = $expunit, !7 = $i, !8 = $thecash
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV_INIT                                            !1      1
    4     2        INIT_FCALL                                                   'number_format'
          3        CAST                                              5  ~9      !0
          4        SEND_VAL                                                     ~9
          5        SEND_VAL                                                     2
          6        SEND_VAL                                                     '.'
          7        SEND_VAL                                                     ''
          8        DO_ICALL                                             $10     
          9        ASSIGN                                                       !2, $10
    5    10        FRAMELESS_ICALL_2                strpos              ~12     !0, '.'
         11        TYPE_CHECK                                      1018          ~12
         12      > JMPZ                                                         ~13, ->17
    6    13    >   FRAMELESS_ICALL_2                strpos              ~14     !2, '.'
         14        FRAMELESS_ICALL_3                substr              ~15     !2, 0
         15        OP_DATA                                                      ~14
         16        ASSIGN                                                       !0, ~15
    9    17    >   IS_EQUAL                                                     !1, 1
         18      > JMPZ                                                         ~17, ->77
   10    19    >   ASSIGN                                                       !3, ''
   11    20        STRLEN                                               ~19     !0
         21        IS_SMALLER                                                   3, ~19
         22      > JMPZ                                                         ~20, ->71
   12    23    >   STRLEN                                               ~21     !0
         24        SUB                                                  ~22     ~21, 3
         25        STRLEN                                               ~23     !0
         26        FRAMELESS_ICALL_3                substr              ~24     !0, ~22
         27        OP_DATA                                                      ~23
         28        ASSIGN                                                       !4, ~24
   13    29        STRLEN                                               ~26     !0
         30        SUB                                                  ~27     ~26, 3
         31        FRAMELESS_ICALL_3                substr              ~28     !0, 0
         32        OP_DATA                                                      ~27
         33        ASSIGN                                                       !5, ~28
   14    34        STRLEN                                               ~30     !5
         35        MOD                                                  ~31     ~30, 2
         36        IS_EQUAL                                                     ~31, 1
         37      > JMPZ                                                         ~32, ->41
         38    >   CONCAT                                               ~33     '0', !5
         39        QM_ASSIGN                                            ~34     ~33
         40      > JMP                                                          ->42
         41    >   QM_ASSIGN                                            ~34     !5
         42    >   ASSIGN                                                       !5, ~34
   15    43        INIT_FCALL                                                   'str_split'
         44        SEND_VAR                                                     !5
         45        SEND_VAL                                                     2
         46        DO_ICALL                                             $36     
         47        ASSIGN                                                       !6, $36
   16    48        ASSIGN                                                       !7, 0
         49      > JMP                                                          ->61
   18    50    >   IS_EQUAL                                                     !7, 0
         51      > JMPZ                                                         ~39, ->57
   19    52    >   FETCH_DIM_R                                          ~40     !6, !7
         53        CAST                                              4  ~41     ~40
         54        CONCAT                                               ~42     ~41, '%2C'
         55        ASSIGN_OP                                         8          !3, ~42
   18    56      > JMP                                                          ->60
   21    57    >   FETCH_DIM_R                                          ~44     !6, !7
         58        CONCAT                                               ~45     ~44, '%2C'
         59        ASSIGN_OP                                         8          !3, ~45
   16    60    >   PRE_INC                                                      !7
         61    >   COUNT                                                ~48     !6
         62        IS_SMALLER                                                   !7, ~48
         63      > JMPNZ                                                        ~49, ->50
   24    64    >   CONCAT                                               ~50     '%E2%82%B9', !3
         65        CONCAT                                               ~51     ~50, !4
         66        FRAMELESS_ICALL_2                substr              ~52     !2, -3
         67        CONCAT                                               ~53     ~51, ~52
         68        CONCAT                                               ~54     ~53, '%2F-'
         69        ASSIGN                                                       !8, ~54
   11    70      > JMP                                                          ->76
   26    71    >   CONCAT                                               ~56     '%E2%82%B9', !0
         72        FRAMELESS_ICALL_2                substr              ~57     !2, -3
         73        CONCAT                                               ~58     ~56, ~57
         74        CONCAT                                               ~59     ~58, '%2F-'
         75        ASSIGN                                                       !8, ~59
   28    76    > > RETURN                                                       !8
   30    77    > > RETURN                                                       null

End of function price_format

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
163.13 ms | 1993 KiB | 18 Q