3v4l.org

run code in 300+ PHP versions simultaneously
<?php function price_format($num,$type = 1){ $num_full = number_format($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, strpos($num_full, "."))."/-"; } else { $thecash = "₹".$num.substr($num_full, -3, strpos($num_full, "."))."/-"; } return $thecash; // writes the final format where $currency is the currency symbol. } } echo price_format(1)."<br />"; echo price_format(10)."<br />"; echo price_format(84289.35);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/eNYDl
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, '%3Cbr+%2F%3E'
          4        ECHO                                                     ~1
   33     5        INIT_FCALL                                               'price_format'
          6        SEND_VAL                                                 10
          7        DO_FCALL                                      0  $2      
          8        CONCAT                                           ~3      $2, '%3Cbr+%2F%3E'
          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 = 23
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 105
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 91
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 50, Position 2 = 53
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 54
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 62
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 104
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 64, Position 2 = 69
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 72
Branch analysis from position: 72
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 62
Branch analysis from position: 76
Branch analysis from position: 62
Branch analysis from position: 69
2 jumps found. (Code = 44) Position 1 = 76, Position 2 = 62
Branch analysis from position: 76
Branch analysis from position: 62
Branch analysis from position: 53
1 jumps found. (Code = 42) Position 1 = 73
Branch analysis from position: 73
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/eNYDl
function name:  price_format
number of ops:  106
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        SEND_VAR                                                 !0
          4        SEND_VAL                                                 2
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !2, $9
    5     7        INIT_FCALL                                               'strpos'
          8        SEND_VAR                                                 !0
          9        SEND_VAL                                                 '.'
         10        DO_ICALL                                         $11     
         11        TYPE_CHECK                                  1018          $11
         12      > JMPZ                                                     ~12, ->23
    6    13    >   INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !2
         15        SEND_VAL                                                 0
         16        INIT_FCALL                                               'strpos'
         17        SEND_VAR                                                 !2
         18        SEND_VAL                                                 '.'
         19        DO_ICALL                                         $13     
         20        SEND_VAR                                                 $13
         21        DO_ICALL                                         $14     
         22        ASSIGN                                                   !0, $14
    9    23    >   IS_EQUAL                                                 !1, 1
         24      > JMPZ                                                     ~16, ->105
   10    25    >   ASSIGN                                                   !3, ''
   11    26        STRLEN                                           ~18     !0
         27        IS_SMALLER                                               3, ~18
         28      > JMPZ                                                     ~19, ->91
   12    29    >   INIT_FCALL                                               'substr'
         30        SEND_VAR                                                 !0
         31        STRLEN                                           ~20     !0
         32        SUB                                              ~21     ~20, 3
         33        SEND_VAL                                                 ~21
         34        STRLEN                                           ~22     !0
         35        SEND_VAL                                                 ~22
         36        DO_ICALL                                         $23     
         37        ASSIGN                                                   !4, $23
   13    38        INIT_FCALL                                               'substr'
         39        SEND_VAR                                                 !0
         40        SEND_VAL                                                 0
         41        STRLEN                                           ~25     !0
         42        SUB                                              ~26     ~25, 3
         43        SEND_VAL                                                 ~26
         44        DO_ICALL                                         $27     
         45        ASSIGN                                                   !5, $27
   14    46        STRLEN                                           ~29     !5
         47        MOD                                              ~30     ~29, 2
         48        IS_EQUAL                                                 ~30, 1
         49      > JMPZ                                                     ~31, ->53
         50    >   CONCAT                                           ~32     '0', !5
         51        QM_ASSIGN                                        ~33     ~32
         52      > JMP                                                      ->54
         53    >   QM_ASSIGN                                        ~33     !5
         54    >   ASSIGN                                                   !5, ~33
   15    55        INIT_FCALL                                               'str_split'
         56        SEND_VAR                                                 !5
         57        SEND_VAL                                                 2
         58        DO_ICALL                                         $35     
         59        ASSIGN                                                   !6, $35
   16    60        ASSIGN                                                   !7, 0
         61      > JMP                                                      ->73
   18    62    >   IS_EQUAL                                                 !7, 0
         63      > JMPZ                                                     ~38, ->69
   19    64    >   FETCH_DIM_R                                      ~39     !6, !7
         65        CAST                                          4  ~40     ~39
         66        CONCAT                                           ~41     ~40, '%2C'
         67        ASSIGN_OP                                     8          !3, ~41
   18    68      > JMP                                                      ->72
   21    69    >   FETCH_DIM_R                                      ~43     !6, !7
         70        CONCAT                                           ~44     ~43, '%2C'
         71        ASSIGN_OP                                     8          !3, ~44
   16    72    >   PRE_INC                                                  !7
         73    >   COUNT                                            ~47     !6
         74        IS_SMALLER                                               !7, ~47
         75      > JMPNZ                                                    ~48, ->62
   24    76    >   CONCAT                                           ~49     '%E2%82%B9', !3
         77        CONCAT                                           ~50     ~49, !4
         78        INIT_FCALL                                               'substr'
         79        SEND_VAR                                                 !2
         80        SEND_VAL                                                 -3
         81        INIT_FCALL                                               'strpos'
         82        SEND_VAR                                                 !2
         83        SEND_VAL                                                 '.'
         84        DO_ICALL                                         $51     
         85        SEND_VAR                                                 $51
         86        DO_ICALL                                         $52     
         87        CONCAT                                           ~53     ~50, $52
         88        CONCAT                                           ~54     ~53, '%2F-'
         89        ASSIGN                                                   !8, ~54
   11    90      > JMP                                                      ->104
   26    91    >   CONCAT                                           ~56     '%E2%82%B9', !0
         92        INIT_FCALL                                               'substr'
         93        SEND_VAR                                                 !2
         94        SEND_VAL                                                 -3
         95        INIT_FCALL                                               'strpos'
         96        SEND_VAR                                                 !2
         97        SEND_VAL                                                 '.'
         98        DO_ICALL                                         $57     
         99        SEND_VAR                                                 $57
        100        DO_ICALL                                         $58     
        101        CONCAT                                           ~59     ~56, $58
        102        CONCAT                                           ~60     ~59, '%2F-'
        103        ASSIGN                                                   !8, ~60
   28   104    > > RETURN                                                   !8
   30   105    > > RETURN                                                   null

End of function price_format

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.57 ms | 1020 KiB | 20 Q