3v4l.org

run code in 300+ 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 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 98
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 89
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 53, Position 2 = 56
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 57
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 65
Branch analysis from position: 79
1 jumps found. (Code = 42) Position 1 = 97
Branch analysis from position: 97
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 67, Position 2 = 72
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 75
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 65
Branch analysis from position: 79
Branch analysis from position: 65
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 79, Position 2 = 65
Branch analysis from position: 79
Branch analysis from position: 65
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 76
Branch analysis from position: 76
Branch analysis from position: 89
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 98
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/cEQUI
function name:  price_format
number of ops:  99
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        INIT_FCALL                                               'strpos'
         11        SEND_VAR                                                 !0
         12        SEND_VAL                                                 '.'
         13        DO_ICALL                                         $12     
         14        TYPE_CHECK                                  1018          $12
         15      > JMPZ                                                     ~13, ->26
    6    16    >   INIT_FCALL                                               'substr'
         17        SEND_VAR                                                 !2
         18        SEND_VAL                                                 0
         19        INIT_FCALL                                               'strpos'
         20        SEND_VAR                                                 !2
         21        SEND_VAL                                                 '.'
         22        DO_ICALL                                         $14     
         23        SEND_VAR                                                 $14
         24        DO_ICALL                                         $15     
         25        ASSIGN                                                   !0, $15
    9    26    >   IS_EQUAL                                                 !1, 1
         27      > JMPZ                                                     ~17, ->98
   10    28    >   ASSIGN                                                   !3, ''
   11    29        STRLEN                                           ~19     !0
         30        IS_SMALLER                                               3, ~19
         31      > JMPZ                                                     ~20, ->89
   12    32    >   INIT_FCALL                                               'substr'
         33        SEND_VAR                                                 !0
         34        STRLEN                                           ~21     !0
         35        SUB                                              ~22     ~21, 3
         36        SEND_VAL                                                 ~22
         37        STRLEN                                           ~23     !0
         38        SEND_VAL                                                 ~23
         39        DO_ICALL                                         $24     
         40        ASSIGN                                                   !4, $24
   13    41        INIT_FCALL                                               'substr'
         42        SEND_VAR                                                 !0
         43        SEND_VAL                                                 0
         44        STRLEN                                           ~26     !0
         45        SUB                                              ~27     ~26, 3
         46        SEND_VAL                                                 ~27
         47        DO_ICALL                                         $28     
         48        ASSIGN                                                   !5, $28
   14    49        STRLEN                                           ~30     !5
         50        MOD                                              ~31     ~30, 2
         51        IS_EQUAL                                                 ~31, 1
         52      > JMPZ                                                     ~32, ->56
         53    >   CONCAT                                           ~33     '0', !5
         54        QM_ASSIGN                                        ~34     ~33
         55      > JMP                                                      ->57
         56    >   QM_ASSIGN                                        ~34     !5
         57    >   ASSIGN                                                   !5, ~34
   15    58        INIT_FCALL                                               'str_split'
         59        SEND_VAR                                                 !5
         60        SEND_VAL                                                 2
         61        DO_ICALL                                         $36     
         62        ASSIGN                                                   !6, $36
   16    63        ASSIGN                                                   !7, 0
         64      > JMP                                                      ->76
   18    65    >   IS_EQUAL                                                 !7, 0
         66      > JMPZ                                                     ~39, ->72
   19    67    >   FETCH_DIM_R                                      ~40     !6, !7
         68        CAST                                          4  ~41     ~40
         69        CONCAT                                           ~42     ~41, '%2C'
         70        ASSIGN_OP                                     8          !3, ~42
   18    71      > JMP                                                      ->75
   21    72    >   FETCH_DIM_R                                      ~44     !6, !7
         73        CONCAT                                           ~45     ~44, '%2C'
         74        ASSIGN_OP                                     8          !3, ~45
   16    75    >   PRE_INC                                                  !7
         76    >   COUNT                                            ~48     !6
         77        IS_SMALLER                                               !7, ~48
         78      > JMPNZ                                                    ~49, ->65
   24    79    >   CONCAT                                           ~50     '%E2%82%B9', !3
         80        CONCAT                                           ~51     ~50, !4
         81        INIT_FCALL                                               'substr'
         82        SEND_VAR                                                 !2
         83        SEND_VAL                                                 -3
         84        DO_ICALL                                         $52     
         85        CONCAT                                           ~53     ~51, $52
         86        CONCAT                                           ~54     ~53, '%2F-'
         87        ASSIGN                                                   !8, ~54
   11    88      > JMP                                                      ->97
   26    89    >   CONCAT                                           ~56     '%E2%82%B9', !0
         90        INIT_FCALL                                               'substr'
         91        SEND_VAR                                                 !2
         92        SEND_VAL                                                 -3
         93        DO_ICALL                                         $57     
         94        CONCAT                                           ~58     ~56, $57
         95        CONCAT                                           ~59     ~58, '%2F-'
         96        ASSIGN                                                   !8, ~59
   28    97    > > RETURN                                                   !8
   30    98    > > RETURN                                                   null

End of function price_format

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.48 ms | 1016 KiB | 20 Q