3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getAllWholeWordPos($s,$word){ $retval = false; $b = " "; for ($i=0, $max = strlen( $s ); $i < $max; $i++) { if ( !ctype_alpha( $s[$i] ) ){ $s[$i] = $b; } } while ( ( $pos = stripos( $s, $word) ) !== false ) { $retval[] = $pos; var_dump($word,$retval); for ( $i=0, $max = $pos + 1 + strlen( $word ); $i <= $max; $i++) { $s[$i] = $b; } } return [$retval,$s]; } $str = "TheraininSpainstaysmainlyintheplain."; $d = ["The", "rain", "in", "Spain","stays","mainly","plain"]; $arr = null; for ($i=0, $max = count($d); $i < $max; $i++) { list($r,$str) = getAllWholeWordPos($str,$d[$i]); if (is_array($r)) { foreach ($r as $key => $val) { $arr[$key] = $val; } } else { $arr[$r] = $d[$i]; } } var_dump($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 7
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 27
Branch analysis from position: 19
2 jumps found. (Code = 77) Position 1 = 20, Position 2 = 25
Branch analysis from position: 20
2 jumps found. (Code = 78) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 20
Branch analysis from position: 20
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 7
Branch analysis from position: 33
Branch analysis from position: 7
Branch analysis from position: 25
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 33, Position 2 = 7
Branch analysis from position: 33
Branch analysis from position: 7
filename:       /in/fYdNN
function name:  (null)
number of ops:  37
compiled vars:  !0 = $str, !1 = $d, !2 = $arr, !3 = $i, !4 = $max, !5 = $r, !6 = $val, !7 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   ASSIGN                                                   !0, 'TheraininSpainstaysmainlyintheplain.'
   29     1        ASSIGN                                                   !1, <array>
   31     2        ASSIGN                                                   !2, null
   33     3        ASSIGN                                                   !3, 0
          4        COUNT                                            ~12     !1
          5        ASSIGN                                                   !4, ~12
          6      > JMP                                                      ->31
   34     7    >   INIT_FCALL                                               'getallwholewordpos'
          8        SEND_VAR                                                 !0
          9        FETCH_DIM_R                                      ~14     !1, !3
         10        SEND_VAL                                                 ~14
         11        DO_FCALL                                      0  $15     
         12        FETCH_LIST_R                                     $16     $15, 0
         13        ASSIGN                                                   !5, $16
         14        FETCH_LIST_R                                     $18     $15, 1
         15        ASSIGN                                                   !0, $18
         16        FREE                                                     $15
   35    17        TYPE_CHECK                                  128          !5
         18      > JMPZ                                                     ~20, ->27
   36    19    > > FE_RESET_R                                       $21     !5, ->25
         20    > > FE_FETCH_R                                       ~22     $21, !6, ->25
         21    >   ASSIGN                                                   !7, ~22
   37    22        ASSIGN_DIM                                               !2, !7
         23        OP_DATA                                                  !6
   36    24      > JMP                                                      ->20
         25    >   FE_FREE                                                  $21
         26      > JMP                                                      ->30
   40    27    >   FETCH_DIM_R                                      ~26     !1, !3
         28        ASSIGN_DIM                                               !2, !5
         29        OP_DATA                                                  ~26
   33    30    >   PRE_INC                                                  !3
         31    >   IS_SMALLER                                               !3, !4
         32      > JMPNZ                                                    ~28, ->7
   43    33    >   INIT_FCALL                                               'var_dump'
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                                 
         36      > RETURN                                                   1

Function getallwholewordpos:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 8
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 44, Position 2 = 20
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 32
Branch analysis from position: 37
Branch analysis from position: 32
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 16
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 19, Position 2 = 8
Branch analysis from position: 19
Branch analysis from position: 8
Branch analysis from position: 16
filename:       /in/fYdNN
function name:  getAllWholeWordPos
number of ops:  48
compiled vars:  !0 = $s, !1 = $word, !2 = $retval, !3 = $b, !4 = $i, !5 = $max, !6 = $pos
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <false>
    5     3        ASSIGN                                                   !3, '+'
    7     4        ASSIGN                                                   !4, 0
          5        STRLEN                                           ~10     !0
          6        ASSIGN                                                   !5, ~10
          7      > JMP                                                      ->17
    8     8    >   INIT_FCALL                                               'ctype_alpha'
          9        FETCH_DIM_R                                      ~12     !0, !4
         10        SEND_VAL                                                 ~12
         11        DO_ICALL                                         $13     
         12        BOOL_NOT                                         ~14     $13
         13      > JMPZ                                                     ~14, ->16
    9    14    >   ASSIGN_DIM                                               !0, !4
         15        OP_DATA                                                  !3
    7    16    >   PRE_INC                                                  !4
         17    >   IS_SMALLER                                               !4, !5
         18      > JMPNZ                                                    ~17, ->8
   13    19    > > JMP                                                      ->37
   14    20    >   ASSIGN_DIM                                               !2
         21        OP_DATA                                                  !6
   16    22        INIT_FCALL                                               'var_dump'
         23        SEND_VAR                                                 !1
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                                 
   18    26        ASSIGN                                                   !4, 0
         27        ADD                                              ~21     !6, 1
         28        STRLEN                                           ~22     !1
         29        ADD                                              ~23     ~21, ~22
         30        ASSIGN                                                   !5, ~23
         31      > JMP                                                      ->35
   19    32    >   ASSIGN_DIM                                               !0, !4
         33        OP_DATA                                                  !3
   18    34        PRE_INC                                                  !4
         35    >   IS_SMALLER_OR_EQUAL                                      !4, !5
         36      > JMPNZ                                                    ~27, ->32
   13    37    >   INIT_FCALL                                               'stripos'
         38        SEND_VAR                                                 !0
         39        SEND_VAR                                                 !1
         40        DO_ICALL                                         $28     
         41        ASSIGN                                           ~29     !6, $28
         42        TYPE_CHECK                                  1018          ~29
         43      > JMPNZ                                                    ~30, ->20
   22    44    >   INIT_ARRAY                                       ~31     !2
         45        ADD_ARRAY_ELEMENT                                ~31     !0
         46      > RETURN                                                   ~31
   23    47*     > RETURN                                                   null

End of function getallwholewordpos

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.67 ms | 1398 KiB | 20 Q