3v4l.org

run code in 500+ PHP versions simultaneously
<?php $str='my fictional favourite food is Jellof Rice with salted water but not too much sugar and some rice'; #$str='banana apple mango'; $words=array( 'food', 'water', 'salt' ); function findmatches( $str=false, $search=array()){ if( !empty( $str ) && !empty( $search ) ){ array_walk( $search, function( &$item ){ $item=preg_quote( $item, '@' ); }); $pttn=sprintf('@(\w%s)@',implode( '|', $search ) ); preg_match_all( $pttn, $str, $matches, PREG_OFFSET_CAPTURE ); return !empty( array_filter( $matches ) ) ? $matches[0] : false; } return false; } function showresults( $arr ){ if( !empty( $arr ) ){ foreach( $arr as $i => $v ){ printf('The word "%s" was found at position %s',$v[0],$v[1]); } } } $res=findmatches( $str, $words ); echo $res ? showresults($res) : 'Not found'; ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 13
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5iMk2
function name:  (null)
number of ops:  16
compiled vars:  !0 = $str, !1 = $words, !2 = $res
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, 'my+fictional+favourite+food+is+Jellof+Rice+with+salted+water+but+not+too+much+sugar+and+some+rice'
    5     1        ASSIGN                                                       !1, <array>
   28     2        INIT_FCALL                                                   'findmatches'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0  $5      
          6        ASSIGN                                                       !2, $5
   29     7      > JMPZ                                                         !2, ->13
          8    >   INIT_FCALL                                                   'showresults'
          9        SEND_VAR                                                     !2
         10        DO_FCALL                                          0  $7      
         11        QM_ASSIGN                                            ~8      $7
         12      > JMP                                                          ->14
         13    >   QM_ASSIGN                                            ~8      'Not+found'
         14    >   ECHO                                                         ~8
   30    15      > RETURN                                                       1

Function findmatches:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 46) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 36
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 34
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/5iMk2
function name:  findmatches
number of ops:  38
compiled vars:  !0 = $str, !1 = $search, !2 = $pttn, !3 = $matches
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV_INIT                                            !0      <false>
          1        RECV_INIT                                            !1      <array>
    9     2        ISSET_ISEMPTY_CV                                     ~4      !0
          3        BOOL_NOT                                             ~5      ~4
          4      > JMPZ_EX                                              ~5      ~5, ->8
          5    >   ISSET_ISEMPTY_CV                                     ~6      !1
          6        BOOL_NOT                                             ~7      ~6
          7        BOOL                                                 ~5      ~7
          8    > > JMPZ                                                         ~5, ->36
   10     9    >   INIT_FCALL                                                   'array_walk'
         10        SEND_REF                                                     !1
         11        DECLARE_LAMBDA_FUNCTION                              ~8      [0]
   12    12        SEND_VAL                                                     ~8
   10    13        DO_ICALL                                                     
   13    14        FRAMELESS_ICALL_2                implode             ~10     '%7C', !1
         15        ROPE_INIT                                         3  ~12     '%40%28%5Cw'
         16        ROPE_ADD                                          1  ~12     ~12, ~10
         17        ROPE_END                                          2  ~11     ~12, '%29%40'
         18        ASSIGN                                                       !2, ~11
   14    19        INIT_FCALL                                                   'preg_match_all'
         20        SEND_VAR                                                     !2
         21        SEND_VAR                                                     !0
         22        SEND_REF                                                     !3
         23        SEND_VAL                                                     256
         24        DO_ICALL                                                     
   15    25        INIT_FCALL                                                   'array_filter'
         26        SEND_VAR                                                     !3
         27        DO_ICALL                                             $16     
         28        BOOL_NOT                                             ~17     $16
         29        BOOL_NOT                                             ~18     ~17
         30      > JMPZ                                                         ~18, ->34
         31    >   FETCH_DIM_R                                          ~19     !3, 0
         32        QM_ASSIGN                                            ~20     ~19
         33      > JMP                                                          ->35
         34    >   QM_ASSIGN                                            ~20     <false>
         35    > > RETURN                                                       ~20
   17    36    > > RETURN                                                       <false>
   18    37*     > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5iMk2
function name:  {closure:findmatches():10}
number of ops:  7
compiled vars:  !0 = $item
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
   11     1        INIT_FCALL                                                   'preg_quote'
          2        SEND_VAR                                                     !0
          3        SEND_VAL                                                     '%40'
          4        DO_ICALL                                             $1      
          5        ASSIGN                                                       !0, $1
   12     6      > RETURN                                                       null

End of Dynamic Function 0

End of function findmatches

Function showresults:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 15
Branch analysis from position: 16
filename:       /in/5iMk2
function name:  showresults
number of ops:  17
compiled vars:  !0 = $arr, !1 = $v, !2 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   RECV                                                 !0      
   20     1        ISSET_ISEMPTY_CV                                     ~3      !0
          2        BOOL_NOT                                             ~4      ~3
          3      > JMPZ                                                         ~4, ->16
   21     4    > > FE_RESET_R                                           $5      !0, ->15
          5    > > FE_FETCH_R                                           ~6      $5, !1, ->15
          6    >   ASSIGN                                                       !2, ~6
   22     7        INIT_FCALL                                                   'printf'
          8        SEND_VAL                                                     'The+word+%22%25s%22+was+found+at+position+%25s'
          9        FETCH_DIM_R                                          ~8      !1, 0
         10        SEND_VAL                                                     ~8
         11        FETCH_DIM_R                                          ~9      !1, 1
         12        SEND_VAL                                                     ~9
         13        DO_ICALL                                                     
   21    14      > JMP                                                          ->5
         15    >   FE_FREE                                                      $5
   25    16    > > RETURN                                                       null

End of function showresults

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.17 ms | 1995 KiB | 20 Q