3v4l.org

run code in 500+ PHP versions simultaneously
<?php function lookAndSay(int $n): string { if ($n <= 1) return '1'; $r = $lastSeq = '1'; while($n-- > 0) $r .= ' '.($lastSeq = tokenize($lastSeq)); return $r; } function tokenize(string $str): string { $r = ''; $c = 1; for ($i = 0; $i < strlen($str); $i++) { if($str[$i] == ($str[$i + 1] ?? '')) { $c++; continue; } ($r .= $c.$str[$i]) && ($c = 1); } return $r; } echo lookAndSay(3);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/A7eA2
function name:  (null)
number of ops:  5
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   22     0  E >   INIT_FCALL                                                   'lookandsay'
          1        SEND_VAL                                                     3
          2        DO_FCALL                                          0  $0      
          3        ECHO                                                         $0
          4      > RETURN                                                       1

Function lookandsay:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 4
Branch analysis from position: 3
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 7
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 7
Branch analysis from position: 16
Branch analysis from position: 7
filename:       /in/A7eA2
function name:  lookAndSay
number of ops:  20
compiled vars:  !0 = $n, !1 = $r, !2 = $lastSeq
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   RECV                                                 !0      
    3     1        IS_SMALLER_OR_EQUAL                                          !0, 1
          2      > JMPZ                                                         ~3, ->4
          3    > > RETURN                                                       '1'
    4     4    >   ASSIGN                                               ~4      !2, '1'
          5        ASSIGN                                                       !1, ~4
    5     6      > JMP                                                          ->13
          7    >   INIT_FCALL_BY_NAME                                           'tokenize'
          8        SEND_VAR_EX                                                  !2
          9        DO_FCALL                                          0  $6      
         10        ASSIGN                                               ~7      !2, $6
         11        CONCAT                                               ~8      '+', ~7
         12        ASSIGN_OP                                         8          !1, ~8
         13    >   POST_DEC                                             ~10     !0
         14        IS_SMALLER                                                   0, ~10
         15      > JMPNZ                                                        ~11, ->7
    6    16    >   VERIFY_RETURN_TYPE                                           !1
         17      > RETURN                                                       !1
    7    18*       VERIFY_RETURN_TYPE                                           
         19*     > RETURN                                                       null

End of function lookandsay

Function tokenize:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 5
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 14
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 5
Branch analysis from position: 24
Branch analysis from position: 5
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 44) Position 1 = 24, Position 2 = 5
Branch analysis from position: 24
Branch analysis from position: 5
Branch analysis from position: 20
filename:       /in/A7eA2
function name:  tokenize
number of ops:  28
compiled vars:  !0 = $str, !1 = $r, !2 = $c, !3 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    9     0  E >   RECV                                                 !0      
   10     1        ASSIGN                                                       !1, ''
   11     2        ASSIGN                                                       !2, 1
   12     3        ASSIGN                                                       !3, 0
          4      > JMP                                                          ->21
   13     5    >   FETCH_DIM_R                                          ~7      !0, !3
          6        ADD                                                  ~8      !3, 1
          7        FETCH_DIM_IS                                         ~9      !0, ~8
          8        COALESCE                                             ~10     ~9
          9        QM_ASSIGN                                            ~10     ''
         10        IS_EQUAL                                                     ~7, ~10
         11      > JMPZ                                                         ~11, ->14
   14    12    >   PRE_INC                                                      !2
   15    13      > JMP                                                          ->20
   17    14    >   FETCH_DIM_R                                          ~13     !0, !3
         15        CONCAT                                               ~14     !2, ~13
         16        ASSIGN_OP                                         8  ~15     !1, ~14
         17      > JMPZ_EX                                              ~15     ~15, ->20
         18    >   ASSIGN                                               ~16     !2, 1
         19        BOOL                                                 ~15     ~16
   12    20    >   PRE_INC                                                      !3
         21    >   STRLEN                                               ~18     !0
         22        IS_SMALLER                                                   !3, ~18
         23      > JMPNZ                                                        ~19, ->5
   19    24    >   VERIFY_RETURN_TYPE                                           !1
         25      > RETURN                                                       !1
   20    26*       VERIFY_RETURN_TYPE                                           
         27*     > RETURN                                                       null

End of function tokenize

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
175.95 ms | 1489 KiB | 14 Q