3v4l.org

run code in 500+ PHP versions simultaneously
<?php function create_word(string $alphabet, int $index): string { $base = mb_strlen($alphabet); $fix = 1; $length = 1; foreach (range(1, $base) as $k) { $pow = pow($base, $k); if ($fix + $pow <= $index) { $fix += $pow; $length++; } else { break; } } $template = sprintf("%0{$length}d", base_convert($index - $fix, 10, $base)); $replace = implode('', range(0, $base)); return strtr($template, $replace, $alphabet); } for ($i = 1; $i <= 81; $i++) { echo $i . ' = '. create_word("abc", $i) . \PHP_EOL; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 11
Branch analysis from position: 11
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 2
2 jumps found. (Code = 44) Position 1 = 13, Position 2 = 2
Branch analysis from position: 13
Branch analysis from position: 2
filename:       /in/m12ke
function name:  (null)
number of ops:  14
compiled vars:  !0 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   ASSIGN                                                       !0, 1
          1      > JMP                                                          ->11
   24     2    >   CONCAT                                               ~2      !0, '+%3D+'
          3        INIT_FCALL                                                   'create_word'
          4        SEND_VAL                                                     'abc'
          5        SEND_VAR                                                     !0
          6        DO_FCALL                                          0  $3      
          7        CONCAT                                               ~4      ~2, $3
          8        CONCAT                                               ~5      ~4, '%0A'
          9        ECHO                                                         ~5
   23    10        PRE_INC                                                      !0
         11    >   IS_SMALLER_OR_EQUAL                                          !0, 81
         12      > JMPNZ                                                        ~7, ->2
   25    13    > > RETURN                                                       1

Function create_word:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 27
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 27
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 25
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 27
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
Branch analysis from position: 27
filename:       /in/m12ke
function name:  create_word
number of ops:  54
compiled vars:  !0 = $alphabet, !1 = $index, !2 = $base, !3 = $fix, !4 = $length, !5 = $k, !6 = $pow, !7 = $template, !8 = $replace
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
    5     2        INIT_FCALL                                                   'mb_strlen'
          3        SEND_VAR                                                     !0
          4        DO_ICALL                                             $9      
          5        ASSIGN                                                       !2, $9
    6     6        ASSIGN                                                       !3, 1
    7     7        ASSIGN                                                       !4, 1
    8     8        INIT_FCALL                                                   'range'
          9        SEND_VAL                                                     1
         10        SEND_VAR                                                     !2
         11        DO_ICALL                                             $13     
         12      > FE_RESET_R                                           $14     $13, ->27
         13    > > FE_FETCH_R                                                   $14, !5, ->27
    9    14    >   INIT_FCALL                                                   'pow'
         15        SEND_VAR                                                     !2
         16        SEND_VAR                                                     !5
         17        DO_ICALL                                             $15     
         18        ASSIGN                                                       !6, $15
   10    19        ADD                                                  ~17     !3, !6
         20        IS_SMALLER_OR_EQUAL                                          ~17, !1
         21      > JMPZ                                                         ~18, ->25
   11    22    >   ASSIGN_OP                                         1          !3, !6
   12    23        PRE_INC                                                      !4
   10    24      > JMP                                                          ->26
   14    25    > > JMP                                                          ->27
    8    26    > > JMP                                                          ->13
         27    >   FE_FREE                                                      $14
   17    28        INIT_FCALL                                                   'sprintf'
         29        ROPE_INIT                                         3  ~22     '%250'
         30        ROPE_ADD                                          1  ~22     ~22, !4
         31        ROPE_END                                          2  ~21     ~22, 'd'
         32        SEND_VAL                                                     ~21
         33        INIT_FCALL                                                   'base_convert'
         34        SUB                                                  ~24     !1, !3
         35        SEND_VAL                                                     ~24
         36        SEND_VAL                                                     10
         37        SEND_VAR                                                     !2
         38        DO_ICALL                                             $25     
         39        SEND_VAR                                                     $25
         40        DO_ICALL                                             $26     
         41        ASSIGN                                                       !7, $26
   18    42        INIT_FCALL                                                   'range'
         43        SEND_VAL                                                     0
         44        SEND_VAR                                                     !2
         45        DO_ICALL                                             $28     
         46        FRAMELESS_ICALL_2                implode             ~29     '', $28
         47        ASSIGN                                                       !8, ~29
   20    48        FRAMELESS_ICALL_3                strtr               ~31     !7, !8
         49        OP_DATA                                                      !0
         50        VERIFY_RETURN_TYPE                                           ~31
         51      > RETURN                                                       ~31
   21    52*       VERIFY_RETURN_TYPE                                           
         53*     > RETURN                                                       null

End of function create_word

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.93 ms | 3601 KiB | 19 Q