3v4l.org

run code in 300+ PHP versions simultaneously
<?php $h = ""; $rest = ""; $D = [0 => "zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen", "twenty", 30 => "thirty", 40 => "forty", 50 => "fifty", 60 => "sixty", 70 => "seventy",80 => "eighty",90 => "ninety"]; function validate($x, $len) { $retval = null; if (!isset($x)){ echo "\$x is unset\n"; $retval = false; } else if (is_float($x) ){ echo "Floats are unsupported in this version.\n"; $retval = false; } else if ( $len == 0) { echo "Empty value\n"; $retval = false; } else if ( $x < 0) { echo "Negative numbers are currently unsupported.\n"; $retval = false; } else if ($len > 4) { echo "Numbers with more than 4 digits are unsupported\n"; $retval = false; } else { $retval = true; } return $retval; } function num2en( $x, $words) { $len = strlen($x); // Get number of digits in given number $retval = null; if( validate($x, $len) === false) { return false; } // handle number by length and digit(s) switch($len) { case 1: $retval = "$words[$x]\n"; break; case 2: if ( isset($words[$x]) ) { $retval = "$words[$x]\n"; } else if( preg_match('/^(.)(.)$/', $x, $matches ) ){ $retval = $words[ $matches[1] . '0'] . '-' . $words[ $matches[2]] . "\n"; } break; case 3: preg_match('/^(.)(..)$/',$x,$matches ); [$h, $rest] = [ $words[$matches[1]]." hundred", $matches[2] ]; if ( strcmp( $rest,'00') === 0 ) { $retval = $h; } if ($h == '0') { $retval = "and " . num2en(0 + $rest, $words); } $retval = $h . " and " . num2en( 0 + $rest, $words); break; case 4: $firstDigit = preg_split("//", $x, -1, PREG_SPLIT_NO_EMPTY )[0]; $retval = $words[$firstDigit] . " thousand " . num2en(substr($x,1,3), $words); break; } return $retval; } $bla; echo @num2en( $bla, $D ); echo num2en( -13, $D ); echo num2en( 1.5, $D ); echo num2en( 1, $D ); echo num2en( 10, $D ); echo num2en( 101, $D ); echo num2en( 1203, $D); echo num2en( 9999, $D); echo num2en( 19999, $D);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7gMlB
function name:  (null)
number of ops:  51
compiled vars:  !0 = $h, !1 = $rest, !2 = $D, !3 = $bla
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, ''
    4     1        ASSIGN                                                   !1, ''
    6     2        ASSIGN                                                   !2, <array>
   87     3        BEGIN_SILENCE                                    ~7      
          4        INIT_FCALL                                               'num2en'
          5        SEND_VAR                                                 !3
          6        SEND_VAR                                                 !2
          7        DO_FCALL                                      0  $8      
          8        END_SILENCE                                              ~7
          9        ECHO                                                     $8
   88    10        INIT_FCALL                                               'num2en'
         11        SEND_VAL                                                 -13
         12        SEND_VAR                                                 !2
         13        DO_FCALL                                      0  $9      
         14        ECHO                                                     $9
   89    15        INIT_FCALL                                               'num2en'
         16        SEND_VAL                                                 1.5
         17        SEND_VAR                                                 !2
         18        DO_FCALL                                      0  $10     
         19        ECHO                                                     $10
   90    20        INIT_FCALL                                               'num2en'
         21        SEND_VAL                                                 1
         22        SEND_VAR                                                 !2
         23        DO_FCALL                                      0  $11     
         24        ECHO                                                     $11
   91    25        INIT_FCALL                                               'num2en'
         26        SEND_VAL                                                 10
         27        SEND_VAR                                                 !2
         28        DO_FCALL                                      0  $12     
         29        ECHO                                                     $12
   92    30        INIT_FCALL                                               'num2en'
         31        SEND_VAL                                                 101
         32        SEND_VAR                                                 !2
         33        DO_FCALL                                      0  $13     
         34        ECHO                                                     $13
   93    35        INIT_FCALL                                               'num2en'
         36        SEND_VAL                                                 1203
         37        SEND_VAR                                                 !2
         38        DO_FCALL                                      0  $14     
         39        ECHO                                                     $14
   94    40        INIT_FCALL                                               'num2en'
         41        SEND_VAL                                                 9999
         42        SEND_VAR                                                 !2
         43        DO_FCALL                                      0  $15     
         44        ECHO                                                     $15
   95    45        INIT_FCALL                                               'num2en'
         46        SEND_VAL                                                 19999
         47        SEND_VAR                                                 !2
         48        DO_FCALL                                      0  $16     
         49        ECHO                                                     $16
         50      > RETURN                                                   1

Function validate:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 9
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 29
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/7gMlB
function name:  validate
number of ops:  32
compiled vars:  !0 = $x, !1 = $len, !2 = $retval
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   12     2        ASSIGN                                                   !2, null
   14     3        ISSET_ISEMPTY_CV                                 ~4      !0
          4        BOOL_NOT                                         ~5      ~4
          5      > JMPZ                                                     ~5, ->9
   15     6    >   ECHO                                                     '%24x+is+unset%0A'
   16     7        ASSIGN                                                   !2, <false>
          8      > JMP                                                      ->30
   19     9    >   TYPE_CHECK                                   32          !0
         10      > JMPZ                                                     ~7, ->14
   20    11    >   ECHO                                                     'Floats+are+unsupported+in+this+version.%0A'
   21    12        ASSIGN                                                   !2, <false>
         13      > JMP                                                      ->30
   24    14    >   IS_EQUAL                                                 !1, 0
         15      > JMPZ                                                     ~9, ->19
   25    16    >   ECHO                                                     'Empty+value%0A'
   26    17        ASSIGN                                                   !2, <false>
         18      > JMP                                                      ->30
   29    19    >   IS_SMALLER                                               !0, 0
         20      > JMPZ                                                     ~11, ->24
   30    21    >   ECHO                                                     'Negative+numbers+are+currently+unsupported.%0A'
   31    22        ASSIGN                                                   !2, <false>
         23      > JMP                                                      ->30
   34    24    >   IS_SMALLER                                               4, !1
         25      > JMPZ                                                     ~13, ->29
   35    26    >   ECHO                                                     'Numbers+with+more+than+4+digits+are+unsupported%0A'
   36    27        ASSIGN                                                   !2, <false>
         28      > JMP                                                      ->30
   39    29    >   ASSIGN                                                   !2, <true>
   41    30    > > RETURN                                                   !2
   42    31*     > RETURN                                                   null

End of function validate

Function num2en:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 12
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 44) Position 1 = 14, Position 2 = 21
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 26
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 18, Position 2 = 49
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 20, Position 2 = 90
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 90
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
Branch analysis from position: 49
2 jumps found. (Code = 43) Position 1 = 71, Position 2 = 72
Branch analysis from position: 71
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 81
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
Branch analysis from position: 81
Branch analysis from position: 72
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 33
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 48
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
Branch analysis from position: 48
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 112
Branch analysis from position: 112
filename:       /in/7gMlB
function name:  num2en
number of ops:  114
compiled vars:  !0 = $x, !1 = $words, !2 = $len, !3 = $retval, !4 = $matches, !5 = $h, !6 = $rest, !7 = $firstDigit
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   44     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   45     2        STRLEN                                           ~8      !0
          3        ASSIGN                                                   !2, ~8
   46     4        ASSIGN                                                   !3, null
   48     5        INIT_FCALL                                               'validate'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !2
          8        DO_FCALL                                      0  $11     
          9        TYPE_CHECK                                    4          $11
         10      > JMPZ                                                     ~12, ->12
   49    11    > > RETURN                                                   <false>
   55    12    >   IS_EQUAL                                                 !2, 1
         13      > JMPNZ                                                    ~13, ->21
   58    14    >   IS_EQUAL                                                 !2, 2
         15      > JMPNZ                                                    ~13, ->26
   67    16    >   IS_EQUAL                                                 !2, 3
         17      > JMPNZ                                                    ~13, ->49
   78    18    >   IS_EQUAL                                                 !2, 4
         19      > JMPNZ                                                    ~13, ->90
         20    > > JMP                                                      ->112
   56    21    >   FETCH_DIM_R                                      ~14     !1, !0
         22        NOP                                                      
         23        FAST_CONCAT                                      ~15     ~14, '%0A'
         24        ASSIGN                                                   !3, ~15
   57    25      > JMP                                                      ->112
   59    26    >   ISSET_ISEMPTY_DIM_OBJ                         0          !1, !0
         27      > JMPZ                                                     ~17, ->33
   60    28    >   FETCH_DIM_R                                      ~18     !1, !0
         29        NOP                                                      
         30        FAST_CONCAT                                      ~19     ~18, '%0A'
         31        ASSIGN                                                   !3, ~19
         32      > JMP                                                      ->48
   63    33    >   INIT_FCALL                                               'preg_match'
         34        SEND_VAL                                                 '%2F%5E%28.%29%28.%29%24%2F'
         35        SEND_VAR                                                 !0
         36        SEND_REF                                                 !4
         37        DO_ICALL                                         $21     
         38      > JMPZ                                                     $21, ->48
   64    39    >   FETCH_DIM_R                                      ~22     !4, 1
         40        CONCAT                                           ~23     ~22, '0'
         41        FETCH_DIM_R                                      ~24     !1, ~23
         42        CONCAT                                           ~25     ~24, '-'
         43        FETCH_DIM_R                                      ~26     !4, 2
         44        FETCH_DIM_R                                      ~27     !1, ~26
         45        CONCAT                                           ~28     ~25, ~27
         46        CONCAT                                           ~29     ~28, '%0A'
         47        ASSIGN                                                   !3, ~29
   66    48    > > JMP                                                      ->112
   68    49    >   INIT_FCALL                                               'preg_match'
         50        SEND_VAL                                                 '%2F%5E%28.%29%28..%29%24%2F'
         51        SEND_VAR                                                 !0
         52        SEND_REF                                                 !4
         53        DO_ICALL                                                 
   69    54        FETCH_DIM_R                                      ~32     !4, 1
         55        FETCH_DIM_R                                      ~33     !1, ~32
         56        CONCAT                                           ~34     ~33, '+hundred'
         57        INIT_ARRAY                                       ~35     ~34
         58        FETCH_DIM_R                                      ~36     !4, 2
         59        ADD_ARRAY_ELEMENT                                ~35     ~36
         60        FETCH_LIST_R                                     $37     ~35, 0
         61        ASSIGN                                                   !5, $37
         62        FETCH_LIST_R                                     $39     ~35, 1
         63        ASSIGN                                                   !6, $39
         64        FREE                                                     ~35
   70    65        INIT_FCALL                                               'strcmp'
         66        SEND_VAR                                                 !6
         67        SEND_VAL                                                 '00'
         68        DO_ICALL                                         $41     
         69        IS_IDENTICAL                                             $41, 0
         70      > JMPZ                                                     ~42, ->72
   71    71    >   ASSIGN                                                   !3, !5
   73    72    >   IS_EQUAL                                                 !5, '0'
         73      > JMPZ                                                     ~44, ->81
   74    74    >   INIT_FCALL_BY_NAME                                       'num2en'
         75        ADD                                              ~45     0, !6
         76        SEND_VAL_EX                                              ~45
         77        SEND_VAR_EX                                              !1
         78        DO_FCALL                                      0  $46     
         79        CONCAT                                           ~47     'and+', $46
         80        ASSIGN                                                   !3, ~47
   76    81    >   CONCAT                                           ~49     !5, '+and+'
         82        INIT_FCALL_BY_NAME                                       'num2en'
         83        ADD                                              ~50     0, !6
         84        SEND_VAL_EX                                              ~50
         85        SEND_VAR_EX                                              !1
         86        DO_FCALL                                      0  $51     
         87        CONCAT                                           ~52     ~49, $51
         88        ASSIGN                                                   !3, ~52
   77    89      > JMP                                                      ->112
   79    90    >   INIT_FCALL                                               'preg_split'
         91        SEND_VAL                                                 '%2F%2F'
         92        SEND_VAR                                                 !0
         93        SEND_VAL                                                 -1
         94        SEND_VAL                                                 1
         95        DO_ICALL                                         $54     
         96        FETCH_DIM_R                                      ~55     $54, 0
         97        ASSIGN                                                   !7, ~55
   80    98        FETCH_DIM_R                                      ~57     !1, !7
         99        CONCAT                                           ~58     ~57, '+thousand+'
        100        INIT_FCALL_BY_NAME                                       'num2en'
        101        INIT_FCALL                                               'substr'
        102        SEND_VAR                                                 !0
        103        SEND_VAL                                                 1
        104        SEND_VAL                                                 3
        105        DO_ICALL                                         $59     
        106        SEND_VAR_NO_REF_EX                                       $59
        107        SEND_VAR_EX                                              !1
        108        DO_FCALL                                      0  $60     
        109        CONCAT                                           ~61     ~58, $60
        110        ASSIGN                                                   !3, ~61
   81   111      > JMP                                                      ->112
   83   112    > > RETURN                                                   !3
   84   113*     > RETURN                                                   null

End of function num2en

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
178.63 ms | 1419 KiB | 31 Q