3v4l.org

run code in 300+ PHP versions simultaneously
<?php $splitby = array('these','are','the','words','to','split','by'); $text = 'This is the string which needs to be split by the above words.'; $split = explode(' ', $text); $result = array(); $temp = array(); foreach ($split as $s) { if (in_array($s, $splitby)) { if (sizeof($temp) > 0) { $result[] = implode(' ', $temp); $temp = array(); } } else { $temp[] = $s; } } if (sizeof($temp) > 0) { $result[] = implode(' ', $temp); } var_dump($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 30
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 30
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 27
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 26
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 40
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 30
filename:       /in/GDklb
function name:  (null)
number of ops:  44
compiled vars:  !0 = $splitby, !1 = $text, !2 = $split, !3 = $result, !4 = $temp, !5 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !1, 'This+is+the+string+which+needs+to+be+split+by+the+above+words.'
    5     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !2, $8
    6     7        ASSIGN                                                   !3, <array>
    7     8        ASSIGN                                                   !4, <array>
    9     9      > FE_RESET_R                                       $12     !2, ->30
         10    > > FE_FETCH_R                                               $12, !5, ->30
   11    11    >   INIT_FCALL                                               'in_array'
         12        SEND_VAR                                                 !5
         13        SEND_VAR                                                 !0
         14        DO_ICALL                                         $13     
         15      > JMPZ                                                     $13, ->27
   12    16    >   COUNT                                            ~14     !4
         17        IS_SMALLER                                               0, ~14
         18      > JMPZ                                                     ~15, ->26
   13    19    >   INIT_FCALL                                               'implode'
         20        SEND_VAL                                                 '+'
         21        SEND_VAR                                                 !4
         22        DO_ICALL                                         $17     
         23        ASSIGN_DIM                                               !3
         24        OP_DATA                                                  $17
   14    25        ASSIGN                                                   !4, <array>
         26    > > JMP                                                      ->29
   17    27    >   ASSIGN_DIM                                               !4
         28        OP_DATA                                                  !5
    9    29    > > JMP                                                      ->10
         30    >   FE_FREE                                                  $12
   21    31        COUNT                                            ~20     !4
         32        IS_SMALLER                                               0, ~20
         33      > JMPZ                                                     ~21, ->40
   22    34    >   INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '+'
         36        SEND_VAR                                                 !4
         37        DO_ICALL                                         $23     
         38        ASSIGN_DIM                                               !3
         39        OP_DATA                                                  $23
   25    40    >   INIT_FCALL                                               'var_dump'
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                                 
         43      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.94 ms | 1392 KiB | 21 Q