3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = 'VALONE VALTWO HERE VAL THREE HERE'; $expected = ["VALONE ", "VALTWO HERE ", "VAL THREE HERE"]; var_dump($result = betterWay($str, [8, 15, 14]), $result === $expected); function betterWay($string, $offsets) { $pos = 0; $res = []; foreach($offsets as $k => $v) { $res[] = substr($string, $pos, $v); $pos+=$v; } return $res; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/NVulg
function name:  (null)
number of ops:  13
compiled vars:  !0 = $str, !1 = $expected, !2 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'VALONE++VALTWO+HERE++++VAL+THREE+HERE'
    4     1        ASSIGN                                                   !1, <array>
    5     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL_BY_NAME                                       'betterWay'
          4        SEND_VAR_EX                                              !0
          5        SEND_VAL_EX                                              <array>
          6        DO_FCALL                                      0  $5      
          7        ASSIGN                                           ~6      !2, $5
          8        SEND_VAL                                                 ~6
          9        IS_IDENTICAL                                     ~7      !2, !1
         10        SEND_VAL                                                 ~7
         11        DO_ICALL                                                 
   15    12      > RETURN                                                   1

Function betterway:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 16
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/NVulg
function name:  betterWay
number of ops:  19
compiled vars:  !0 = $string, !1 = $offsets, !2 = $pos, !3 = $res, !4 = $v, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    8     2        ASSIGN                                                   !2, 0
    9     3        ASSIGN                                                   !3, <array>
   10     4      > FE_RESET_R                                       $8      !1, ->16
          5    > > FE_FETCH_R                                       ~9      $8, !4, ->16
          6    >   ASSIGN                                                   !5, ~9
   11     7        INIT_FCALL                                               'substr'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !4
         11        DO_ICALL                                         $12     
         12        ASSIGN_DIM                                               !3
         13        OP_DATA                                                  $12
   12    14        ASSIGN_OP                                     1          !2, !4
   10    15      > JMP                                                      ->5
         16    >   FE_FREE                                                  $8
   14    17      > RETURN                                                   !3
   15    18*     > RETURN                                                   null

End of function betterway

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
170.61 ms | 1396 KiB | 17 Q