3v4l.org

run code in 300+ PHP versions simultaneously
<?php $number = 1000000; $hyphen = '-'; $conjunction = ' and '; $separator = ', '; $negative = 'negative '; $decimal = ' point '; $dictionary = array( 0 => 'zero', 1 => 'one', 2 => 'two', 3 => 'three', 4 => 'four', 5 => 'five', 6 => 'six', 7 => 'seven', 8 => 'eight', 9 => 'nine', 10 => 'ten', 11 => 'eleven', 12 => 'twelve', 13 => 'thirteen', 14 => 'fourteen', 15 => 'fifteen', 16 => 'sixteen', 17 => 'seventeen', 18 => 'eighteen', 19 => 'nineteen', 20 => 'twenty', 30 => 'thirty', 40 => 'fourty', 50 => 'fifty', 60 => 'sixty', 70 => 'seventy', 80 => 'eighty', 90 => 'ninety', 100 => 'hundred', 1000 => 'thousand', 100000 => 'lakhs', 10000000 => 'cores', 1000000000 => 'billion', 1000000000000 => 'trillion', 1000000000000000 => 'quadrillion', 1000000000000000000 => 'quintillion' ); if (!is_numeric($number)) { return false; } if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) { // overflow trigger_error( 'convert_number_to_words only accepts numbers between -' . PHP_INT_MAX . ' and ' . PHP_INT_MAX, E_USER_WARNING ); return false; } if ($number < 0) { return $negative . convert_number_to_words(abs($number)); } $string = $fraction = null; if (strpos($number, '.') !== false) { list($number, $fraction) = explode('.', $number); } switch (true) { case $number < 21: $string = $dictionary[$number]; break; case $number < 100: $tens = ((int) ($number / 10)) * 10; $units = $number % 10; $string = $dictionary[$tens]; if ($units) { $string .= $hyphen . $dictionary[$units]; } break; case $number < 1000: $hundreds = $number / 100; $remainder = $number % 100; $string = $dictionary[$hundreds] . ' ' . $dictionary[100]; if ($remainder) { $string .= $conjunction . convert_number_to_words($remainder); } break; default: $pow = floor(log($number, 10)); $remainer_val = 100; if($pow > 3 && $pow < 6 ) { $baseUnit = pow(1000, floor(log($number, 1000))); } else if($pow > 5 && $pow < 8 ) { $baseUnit = 100000; $remainer_val = 10; } else if($pow > 7 && $pow < 10 ) { $baseUnit = 10000000; $remainer_val = 10; } else { $baseUnit = pow(1000, floor(log($number, 1000))); } $numBaseUnits = (int) ($number / $baseUnit); $remainder = $number % $baseUnit; $string = convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit]; if ($remainder) { $string .= $remainder < $remainer_val ? $conjunction : $separator; $string .= convert_number_to_words($remainder); } break; } if (null !== $fraction && is_numeric($fraction)) { $string .= $decimal; $words = array(); foreach (str_split((string) $fraction) as $number) { $words[] = $dictionary[$number]; } $string .= implode(' ', $words); } echo $string;
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 13
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 46) Position 1 = 15, Position 2 = 18
Branch analysis from position: 15
2 jumps found. (Code = 47) Position 1 = 19, Position 2 = 22
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 23, Position 2 = 28
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
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 = 62) Position 1 = -2
Branch analysis from position: 38
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 55
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 57, Position 2 = 62
Branch analysis from position: 57
2 jumps found. (Code = 44) Position 1 = 59, Position 2 = 65
Branch analysis from position: 59
2 jumps found. (Code = 44) Position 1 = 61, Position 2 = 78
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
2 jumps found. (Code = 46) Position 1 = 105, Position 2 = 107
Branch analysis from position: 105
2 jumps found. (Code = 43) Position 1 = 108, Position 2 = 121
Branch analysis from position: 108
1 jumps found. (Code = 42) Position 1 = 149
Branch analysis from position: 149
2 jumps found. (Code = 43) Position 1 = 162, Position 2 = 172
Branch analysis from position: 162
2 jumps found. (Code = 43) Position 1 = 164, Position 2 = 166
Branch analysis from position: 164
1 jumps found. (Code = 42) Position 1 = 167
Branch analysis from position: 167
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
2 jumps found. (Code = 46) Position 1 = 175, Position 2 = 179
Branch analysis from position: 175
2 jumps found. (Code = 43) Position 1 = 180, Position 2 = 198
Branch analysis from position: 180
2 jumps found. (Code = 77) Position 1 = 187, Position 2 = 192
Branch analysis from position: 187
2 jumps found. (Code = 78) Position 1 = 188, Position 2 = 192
Branch analysis from position: 188
1 jumps found. (Code = 42) Position 1 = 187
Branch analysis from position: 187
Branch analysis from position: 192
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 192
Branch analysis from position: 198
Branch analysis from position: 179
Branch analysis from position: 166
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
Branch analysis from position: 172
Branch analysis from position: 121
2 jumps found. (Code = 46) Position 1 = 123, Position 2 = 125
Branch analysis from position: 123
2 jumps found. (Code = 43) Position 1 = 126, Position 2 = 129
Branch analysis from position: 126
1 jumps found. (Code = 42) Position 1 = 149
Branch analysis from position: 149
Branch analysis from position: 129
2 jumps found. (Code = 46) Position 1 = 131, Position 2 = 133
Branch analysis from position: 131
2 jumps found. (Code = 43) Position 1 = 134, Position 2 = 137
Branch analysis from position: 134
1 jumps found. (Code = 42) Position 1 = 149
Branch analysis from position: 149
Branch analysis from position: 137
2 jumps found. (Code = 43) Position 1 = 162, Position 2 = 172
Branch analysis from position: 162
Branch analysis from position: 172
Branch analysis from position: 133
Branch analysis from position: 125
Branch analysis from position: 107
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 88, Position 2 = 93
Branch analysis from position: 88
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
Branch analysis from position: 93
Branch analysis from position: 65
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 77
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
Branch analysis from position: 77
Branch analysis from position: 62
1 jumps found. (Code = 42) Position 1 = 173
Branch analysis from position: 173
Branch analysis from position: 55
Branch analysis from position: 22
Branch analysis from position: 18
filename:       /in/23VHl
function name:  (null)
number of ops:  200
compiled vars:  !0 = $number, !1 = $hyphen, !2 = $conjunction, !3 = $separator, !4 = $negative, !5 = $decimal, !6 = $dictionary, !7 = $string, !8 = $fraction, !9 = $tens, !10 = $units, !11 = $hundreds, !12 = $remainder, !13 = $pow, !14 = $remainer_val, !15 = $baseUnit, !16 = $numBaseUnits, !17 = $words
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 1000000
    3     1        ASSIGN                                                   !1, '-'
    4     2        ASSIGN                                                   !2, '+and+'
    5     3        ASSIGN                                                   !3, '%2C+'
    6     4        ASSIGN                                                   !4, 'negative+'
    7     5        ASSIGN                                                   !5, '+point+'
    8     6        ASSIGN                                                   !6, <array>
   47     7        INIT_FCALL                                               'is_numeric'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $25     
         10        BOOL_NOT                                         ~26     $25
         11      > JMPZ                                                     ~26, ->13
   48    12    > > RETURN                                                   <false>
   51    13    >   IS_SMALLER_OR_EQUAL                              ~27     0, !0
         14      > JMPZ_EX                                          ~27     ~27, ->18
         15    >   CAST                                          4  ~28     !0
         16        IS_SMALLER                                       ~29     ~28, 0
         17        BOOL                                             ~27     ~29
         18    > > JMPNZ_EX                                         ~27     ~27, ->22
         19    >   CAST                                          4  ~30     !0
         20        IS_SMALLER                                       ~31     ~30, -9223372036854775807
         21        BOOL                                             ~27     ~31
         22    > > JMPZ                                                     ~27, ->28
   53    23    >   INIT_FCALL                                               'trigger_error'
   54    24        SEND_VAL                                                 'convert_number_to_words+only+accepts+numbers+between+-9223372036854775807+and+9223372036854775807'
   55    25        SEND_VAL                                                 512
         26        DO_ICALL                                                 
   57    27      > RETURN                                                   <false>
   60    28    >   IS_SMALLER                                               !0, 0
         29      > JMPZ                                                     ~33, ->38
   61    30    >   INIT_FCALL_BY_NAME                                       'convert_number_to_words'
         31        INIT_FCALL                                               'abs'
         32        SEND_VAR                                                 !0
         33        DO_ICALL                                         $34     
         34        SEND_VAR_NO_REF_EX                                       $34
         35        DO_FCALL                                      0  $35     
         36        CONCAT                                           ~36     !4, $35
         37      > RETURN                                                   ~36
   64    38    >   ASSIGN                                           ~37     !8, null
         39        ASSIGN                                                   !7, ~37
   66    40        INIT_FCALL                                               'strpos'
         41        SEND_VAR                                                 !0
         42        SEND_VAL                                                 '.'
         43        DO_ICALL                                         $39     
         44        TYPE_CHECK                                  1018          $39
         45      > JMPZ                                                     ~40, ->55
   67    46    >   INIT_FCALL                                               'explode'
         47        SEND_VAL                                                 '.'
         48        SEND_VAR                                                 !0
         49        DO_ICALL                                         $41     
         50        FETCH_LIST_R                                     $42     $41, 0
         51        ASSIGN                                                   !0, $42
         52        FETCH_LIST_R                                     $44     $41, 1
         53        ASSIGN                                                   !8, $44
         54        FREE                                                     $41
   71    55    >   IS_SMALLER                                               !0, 21
         56      > JMPNZ                                                    ~47, ->62
   74    57    >   IS_SMALLER                                               !0, 100
         58      > JMPNZ                                                    ~48, ->65
   82    59    >   IS_SMALLER                                               !0, 1000
         60      > JMPNZ                                                    ~49, ->78
         61    > > JMP                                                      ->94
   72    62    >   FETCH_DIM_R                                      ~50     !6, !0
         63        ASSIGN                                                   !7, ~50
   73    64      > JMP                                                      ->173
   75    65    >   DIV                                              ~52     !0, 10
         66        CAST                                          4  ~53     ~52
         67        MUL                                              ~54     ~53, 10
         68        ASSIGN                                                   !9, ~54
   76    69        MOD                                              ~56     !0, 10
         70        ASSIGN                                                   !10, ~56
   77    71        FETCH_DIM_R                                      ~58     !6, !9
         72        ASSIGN                                                   !7, ~58
   78    73      > JMPZ                                                     !10, ->77
   79    74    >   FETCH_DIM_R                                      ~60     !6, !10
         75        CONCAT                                           ~61     !1, ~60
         76        ASSIGN_OP                                     8          !7, ~61
   81    77    > > JMP                                                      ->173
   83    78    >   DIV                                              ~63     !0, 100
         79        ASSIGN                                                   !11, ~63
   84    80        MOD                                              ~65     !0, 100
         81        ASSIGN                                                   !12, ~65
   85    82        FETCH_DIM_R                                      ~67     !6, !11
         83        CONCAT                                           ~68     ~67, '+'
         84        FETCH_DIM_R                                      ~69     !6, 100
         85        CONCAT                                           ~70     ~68, ~69
         86        ASSIGN                                                   !7, ~70
   86    87      > JMPZ                                                     !12, ->93
   87    88    >   INIT_FCALL_BY_NAME                                       'convert_number_to_words'
         89        SEND_VAR_EX                                              !12
         90        DO_FCALL                                      0  $72     
         91        CONCAT                                           ~73     !2, $72
         92        ASSIGN_OP                                     8          !7, ~73
   89    93    > > JMP                                                      ->173
   91    94    >   INIT_FCALL                                               'floor'
         95        INIT_FCALL                                               'log'
         96        SEND_VAR                                                 !0
         97        SEND_VAL                                                 10
         98        DO_ICALL                                         $75     
         99        SEND_VAR                                                 $75
        100        DO_ICALL                                         $76     
        101        ASSIGN                                                   !13, $76
   92   102        ASSIGN                                                   !14, 100
   93   103        IS_SMALLER                                       ~79     3, !13
        104      > JMPZ_EX                                          ~79     ~79, ->107
        105    >   IS_SMALLER                                       ~80     !13, 6
        106        BOOL                                             ~79     ~80
        107    > > JMPZ                                                     ~79, ->121
   94   108    >   INIT_FCALL                                               'pow'
        109        SEND_VAL                                                 1000
        110        INIT_FCALL                                               'floor'
        111        INIT_FCALL                                               'log'
        112        SEND_VAR                                                 !0
        113        SEND_VAL                                                 1000
        114        DO_ICALL                                         $81     
        115        SEND_VAR                                                 $81
        116        DO_ICALL                                         $82     
        117        SEND_VAR                                                 $82
        118        DO_ICALL                                         $83     
        119        ASSIGN                                                   !15, $83
        120      > JMP                                                      ->149
   96   121    >   IS_SMALLER                                       ~85     5, !13
        122      > JMPZ_EX                                          ~85     ~85, ->125
        123    >   IS_SMALLER                                       ~86     !13, 8
        124        BOOL                                             ~85     ~86
        125    > > JMPZ                                                     ~85, ->129
   97   126    >   ASSIGN                                                   !15, 100000
   98   127        ASSIGN                                                   !14, 10
        128      > JMP                                                      ->149
   99   129    >   IS_SMALLER                                       ~89     7, !13
        130      > JMPZ_EX                                          ~89     ~89, ->133
        131    >   IS_SMALLER                                       ~90     !13, 10
        132        BOOL                                             ~89     ~90
        133    > > JMPZ                                                     ~89, ->137
  100   134    >   ASSIGN                                                   !15, 10000000
  101   135        ASSIGN                                                   !14, 10
        136      > JMP                                                      ->149
  103   137    >   INIT_FCALL                                               'pow'
        138        SEND_VAL                                                 1000
        139        INIT_FCALL                                               'floor'
        140        INIT_FCALL                                               'log'
        141        SEND_VAR                                                 !0
        142        SEND_VAL                                                 1000
        143        DO_ICALL                                         $93     
        144        SEND_VAR                                                 $93
        145        DO_ICALL                                         $94     
        146        SEND_VAR                                                 $94
        147        DO_ICALL                                         $95     
        148        ASSIGN                                                   !15, $95
  105   149    >   DIV                                              ~97     !0, !15
        150        CAST                                          4  ~98     ~97
        151        ASSIGN                                                   !16, ~98
  106   152        MOD                                              ~100    !0, !15
        153        ASSIGN                                                   !12, ~100
  107   154        INIT_FCALL_BY_NAME                                       'convert_number_to_words'
        155        SEND_VAR_EX                                              !16
        156        DO_FCALL                                      0  $102    
        157        CONCAT                                           ~103    $102, '+'
        158        FETCH_DIM_R                                      ~104    !6, !15
        159        CONCAT                                           ~105    ~103, ~104
        160        ASSIGN                                                   !7, ~105
  108   161      > JMPZ                                                     !12, ->172
  109   162    >   IS_SMALLER                                               !12, !14
        163      > JMPZ                                                     ~107, ->166
        164    >   QM_ASSIGN                                        ~108    !2
        165      > JMP                                                      ->167
        166    >   QM_ASSIGN                                        ~108    !3
        167    >   ASSIGN_OP                                     8          !7, ~108
  110   168        INIT_FCALL_BY_NAME                                       'convert_number_to_words'
        169        SEND_VAR_EX                                              !12
        170        DO_FCALL                                      0  $110    
        171        ASSIGN_OP                                     8          !7, $110
  112   172    > > JMP                                                      ->173
  115   173    >   TYPE_CHECK                                  1020  ~112    !8
        174      > JMPZ_EX                                          ~112    ~112, ->179
        175    >   INIT_FCALL                                               'is_numeric'
        176        SEND_VAR                                                 !8
        177        DO_ICALL                                         $113    
        178        BOOL                                             ~112    $113
        179    > > JMPZ                                                     ~112, ->198
  116   180    >   ASSIGN_OP                                     8          !7, !5
  117   181        ASSIGN                                                   !17, <array>
  118   182        INIT_FCALL                                               'str_split'
        183        CAST                                          6  ~116    !8
        184        SEND_VAL                                                 ~116
        185        DO_ICALL                                         $117    
        186      > FE_RESET_R                                       $118    $117, ->192
        187    > > FE_FETCH_R                                               $118, !0, ->192
  119   188    >   FETCH_DIM_R                                      ~120    !6, !0
        189        ASSIGN_DIM                                               !17
        190        OP_DATA                                                  ~120
  118   191      > JMP                                                      ->187
        192    >   FE_FREE                                                  $118
  121   193        INIT_FCALL                                               'implode'
        194        SEND_VAL                                                 '+'
        195        SEND_VAR                                                 !17
        196        DO_ICALL                                         $121    
        197        ASSIGN_OP                                     8          !7, $121
  123   198    >   ECHO                                                     !7
        199      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.04 ms | 1416 KiB | 33 Q