3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str = 'this! string contains, many. words but I want 5'; function get5Words(string $str) { $words = str_word_count($str, 2); $cnt = 0; foreach($words as $strPos => $v) { if($cnt++ === 5) { return substr($str, 0, $strPos-1); } } return $str; } var_dump(get5Words($str));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/N6J2R
function name:  (null)
number of ops:  8
compiled vars:  !0 = $str
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'this%21+string+contains%2C+many.+words+but+I+want+5'
   16     1        INIT_FCALL                                                   'var_dump'
          2        INIT_FCALL                                                   'get5words'
          3        SEND_VAR                                                     !0
          4        DO_FCALL                                          0  $2      
          5        SEND_VAR                                                     $2
          6        DO_ICALL                                                     
          7      > RETURN                                                       1

Function get5words:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 19
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 18
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/N6J2R
function name:  get5Words
number of ops:  22
compiled vars:  !0 = $str, !1 = $words, !2 = $cnt, !3 = $v, !4 = $strPos
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    4     0  E >   RECV                                                 !0      
    5     1        INIT_FCALL                                                   'str_word_count'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     2
          4        DO_ICALL                                             $5      
          5        ASSIGN                                                       !1, $5
    6     6        ASSIGN                                                       !2, 0
    7     7      > FE_RESET_R                                           $8      !1, ->19
          8    > > FE_FETCH_R                                           ~9      $8, !3, ->19
          9    >   ASSIGN                                                       !4, ~9
    8    10        POST_INC                                             ~11     !2
         11        IS_IDENTICAL                                                 ~11, 5
         12      > JMPZ                                                         ~12, ->18
    9    13    >   SUB                                                  ~13     !4, 1
         14        FRAMELESS_ICALL_3                substr              ~14     !0, 0
         15        OP_DATA                                                      ~13
         16        FE_FREE                                                      $8
         17      > RETURN                                                       ~14
    7    18    > > JMP                                                          ->8
         19    >   FE_FREE                                                      $8
   13    20      > RETURN                                                       !0
   14    21*     > RETURN                                                       null

End of function get5words

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.9 ms | 2021 KiB | 16 Q