3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo 'Comma Formatted: ' . nyx_number_format('1.233.332,34', 'comma') . ' - '; echo 'Dot Formatted: ' . nyx_number_format('1,233,332.34', 'dot'); function nyx_number_format($number, $separator = 'dot') { // Default setting $thousand_separator = ','; $decimal_separator = '.'; if ($separator == 'comma') { $thousand_separator = '.'; $decimal_separator = ','; } // Remove the thousand separator $number = str_replace($thousand_separator, '', $number); // Make sure the Decimal separator is correct $number = str_replace($decimal_separator, '.', $number); if ($separator == 'comma') { return number_format($number, 2, ',', '.'); } return number_format($number, 2, '.', ','); }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/XYlS7
function name:  (null)
number of ops:  14
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL_BY_NAME                                       'nyx_number_format'
          1        SEND_VAL_EX                                              '1.233.332%2C34'
          2        SEND_VAL_EX                                              'comma'
          3        DO_FCALL                                      0  $0      
          4        CONCAT                                           ~1      'Comma+Formatted%3A+', $0
          5        CONCAT                                           ~2      ~1, '+-+'
          6        ECHO                                                     ~2
    4     7        INIT_FCALL_BY_NAME                                       'nyx_number_format'
          8        SEND_VAL_EX                                              '1%2C233%2C332.34'
          9        SEND_VAL_EX                                              'dot'
         10        DO_FCALL                                      0  $3      
         11        CONCAT                                           ~4      'Dot+Formatted%3A+', $3
         12        ECHO                                                     ~4
   28    13      > RETURN                                                   1

Function nyx_number_format:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 8
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/XYlS7
function name:  nyx_number_format
number of ops:  37
compiled vars:  !0 = $number, !1 = $separator, !2 = $thousand_separator, !3 = $decimal_separator
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV_INIT                                        !1      'dot'
    9     2        ASSIGN                                                   !2, '%2C'
   10     3        ASSIGN                                                   !3, '.'
   12     4        IS_EQUAL                                                 !1, 'comma'
          5      > JMPZ                                                     ~6, ->8
   13     6    >   ASSIGN                                                   !2, '.'
   14     7        ASSIGN                                                   !3, '%2C'
   18     8    >   INIT_FCALL                                               'str_replace'
          9        SEND_VAR                                                 !2
         10        SEND_VAL                                                 ''
         11        SEND_VAR                                                 !0
         12        DO_ICALL                                         $9      
         13        ASSIGN                                                   !0, $9
   21    14        INIT_FCALL                                               'str_replace'
         15        SEND_VAR                                                 !3
         16        SEND_VAL                                                 '.'
         17        SEND_VAR                                                 !0
         18        DO_ICALL                                         $11     
         19        ASSIGN                                                   !0, $11
   23    20        IS_EQUAL                                                 !1, 'comma'
         21      > JMPZ                                                     ~13, ->29
   24    22    >   INIT_FCALL                                               'number_format'
         23        SEND_VAR                                                 !0
         24        SEND_VAL                                                 2
         25        SEND_VAL                                                 '%2C'
         26        SEND_VAL                                                 '.'
         27        DO_ICALL                                         $14     
         28      > RETURN                                                   $14
   27    29    >   INIT_FCALL                                               'number_format'
         30        SEND_VAR                                                 !0
         31        SEND_VAL                                                 2
         32        SEND_VAL                                                 '.'
         33        SEND_VAL                                                 '%2C'
         34        DO_ICALL                                         $15     
         35      > RETURN                                                   $15
   28    36*     > RETURN                                                   null

End of function nyx_number_format

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.53 ms | 1400 KiB | 17 Q