3v4l.org

run code in 300+ PHP versions simultaneously
<?php function format_num($num, $precision = 2) { if ($num >= 1000 && $num < 1000000) { $n_format = number_format($num/1000,$precision).'K'; } else if ($num >= 1000000 && $num < 1000000000) { $n_format = number_format($num/1000000,$precision).'M'; } else if ($num >= 1000000000) { $n_format=number_format($num/1000000000,$precision).'B'; } else { $n_format = $num; } return $n_format; } echo format_num(1200,1); echo format_num(1230000); echo format_num(1234000000,3);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N7Q5d
function name:  (null)
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   INIT_FCALL                                               'format_num'
          1        SEND_VAL                                                 1200
          2        SEND_VAL                                                 1
          3        DO_FCALL                                      0  $0      
          4        ECHO                                                     $0
   17     5        INIT_FCALL                                               'format_num'
          6        SEND_VAL                                                 1230000
          7        DO_FCALL                                      0  $1      
          8        ECHO                                                     $1
   18     9        INIT_FCALL                                               'format_num'
         10        SEND_VAL                                                 1234000000
         11        SEND_VAL                                                 3
         12        DO_FCALL                                      0  $2      
         13        ECHO                                                     $2
         14      > RETURN                                                   1

Function format_num:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 4, Position 2 = 6
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 15
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
2 jumps found. (Code = 46) Position 1 = 17, Position 2 = 19
Branch analysis from position: 17
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 28
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 38
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
Branch analysis from position: 6
filename:       /in/N7Q5d
function name:  format_num
number of ops:  41
compiled vars:  !0 = $num, !1 = $precision, !2 = $n_format
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      2
    4     2        IS_SMALLER_OR_EQUAL                              ~3      1000, !0
          3      > JMPZ_EX                                          ~3      ~3, ->6
          4    >   IS_SMALLER                                       ~4      !0, 1000000
          5        BOOL                                             ~3      ~4
          6    > > JMPZ                                                     ~3, ->15
    5     7    >   INIT_FCALL                                               'number_format'
          8        DIV                                              ~5      !0, 1000
          9        SEND_VAL                                                 ~5
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $6      
         12        CONCAT                                           ~7      $6, 'K'
         13        ASSIGN                                                   !2, ~7
         14      > JMP                                                      ->39
    6    15    >   IS_SMALLER_OR_EQUAL                              ~9      1000000, !0
         16      > JMPZ_EX                                          ~9      ~9, ->19
         17    >   IS_SMALLER                                       ~10     !0, 1000000000
         18        BOOL                                             ~9      ~10
         19    > > JMPZ                                                     ~9, ->28
    7    20    >   INIT_FCALL                                               'number_format'
         21        DIV                                              ~11     !0, 1000000
         22        SEND_VAL                                                 ~11
         23        SEND_VAR                                                 !1
         24        DO_ICALL                                         $12     
         25        CONCAT                                           ~13     $12, 'M'
         26        ASSIGN                                                   !2, ~13
         27      > JMP                                                      ->39
    8    28    >   IS_SMALLER_OR_EQUAL                                      1000000000, !0
         29      > JMPZ                                                     ~15, ->38
    9    30    >   INIT_FCALL                                               'number_format'
         31        DIV                                              ~16     !0, 1000000000
         32        SEND_VAL                                                 ~16
         33        SEND_VAR                                                 !1
         34        DO_ICALL                                         $17     
         35        CONCAT                                           ~18     $17, 'B'
         36        ASSIGN                                                   !2, ~18
         37      > JMP                                                      ->39
   11    38    >   ASSIGN                                                   !2, !0
   13    39    > > RETURN                                                   !2
   14    40*     > RETURN                                                   null

End of function format_num

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
151.48 ms | 1403 KiB | 18 Q