3v4l.org

run code in 300+ 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 = 40
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 38
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
filename:       /in/5iMk2
function name:  findmatches
number of ops:  42
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, ->40
   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        INIT_FCALL                                               'sprintf'
         15        SEND_VAL                                                 '%40%28%5Cw%25s%29%40'
         16        INIT_FCALL                                               'implode'
         17        SEND_VAL                                                 '%7C'
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $10     
         20        SEND_VAR                                                 $10
         21        DO_ICALL                                         $11     
         22        ASSIGN                                                   !2, $11
   14    23        INIT_FCALL                                               'preg_match_all'
         24        SEND_VAR                                                 !2
         25        SEND_VAR                                                 !0
         26        SEND_REF                                                 !3
         27        SEND_VAL                                                 256
         28        DO_ICALL                                                 
   15    29        INIT_FCALL                                               'array_filter'
         30        SEND_VAR                                                 !3
         31        DO_ICALL                                         $14     
         32        BOOL_NOT                                         ~15     $14
         33        BOOL_NOT                                         ~16     ~15
         34      > JMPZ                                                     ~16, ->38
         35    >   FETCH_DIM_R                                      ~17     !3, 0
         36        QM_ASSIGN                                        ~18     ~17
         37      > JMP                                                      ->39
         38    >   QM_ASSIGN                                        ~18     <false>
         39    > > RETURN                                                   ~18
   17    40    > > RETURN                                                   <false>
   18    41*     > 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}
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.0.0


preferences:
146.96 ms | 1023 KiB | 22 Q