3v4l.org

run code in 300+ PHP versions simultaneously
<?php function substr_count_array( $haystack, $needle ) { $count = 0; foreach ($needle as $substring) { $count += substr_count( $haystack, $substring); } return $count; } $str = 'The fox jumped over the table and ate a frog'; $search = 'fox ate apple'; $words = explode(' ', $search); $result = substr_count_array($str, $words); $total_words = sizeof($words); $relative = ($result / $total_words) * 100; if($relative > 50) { echo 'Related to your query (Total words: '.$total_words.', Words found: '.$result.')'; } else { echo 'Could not find anything related'; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 25
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/u61TK
function name:  (null)
number of ops:  27
compiled vars:  !0 = $str, !1 = $search, !2 = $words, !3 = $result, !4 = $total_words, !5 = $relative
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   ASSIGN                                                   !0, 'The+fox+jumped+over+the+table+and+ate+a+frog'
   13     1        ASSIGN                                                   !1, 'fox+ate+apple'
   15     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $8      
          6        ASSIGN                                                   !2, $8
   17     7        INIT_FCALL                                               'substr_count_array'
          8        SEND_VAR                                                 !0
          9        SEND_VAR                                                 !2
         10        DO_FCALL                                      0  $10     
         11        ASSIGN                                                   !3, $10
   19    12        COUNT                                            ~12     !2
         13        ASSIGN                                                   !4, ~12
   21    14        DIV                                              ~14     !3, !4
         15        MUL                                              ~15     ~14, 100
         16        ASSIGN                                                   !5, ~15
   23    17        IS_SMALLER                                               50, !5
         18      > JMPZ                                                     ~17, ->25
   25    19    >   CONCAT                                           ~18     'Related+to+your+query+%28Total+words%3A+', !4
         20        CONCAT                                           ~19     ~18, '%2C+Words+found%3A+'
         21        CONCAT                                           ~20     ~19, !3
         22        CONCAT                                           ~21     ~20, '%29'
         23        ECHO                                                     ~21
         24      > JMP                                                      ->26
   29    25    >   ECHO                                                     'Could+not+find+anything+related'
   30    26    > > RETURN                                                   1

Function substr_count_array:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 11
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 11
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
filename:       /in/u61TK
function name:  substr_count_array
number of ops:  14
compiled vars:  !0 = $haystack, !1 = $needle, !2 = $count, !3 = $substring
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, 0
    5     3      > FE_RESET_R                                       $5      !1, ->11
          4    > > FE_FETCH_R                                               $5, !3, ->11
    6     5    >   INIT_FCALL                                               'substr_count'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $6      
          9        ASSIGN_OP                                     1          !2, $6
    5    10      > JMP                                                      ->4
         11    >   FE_FREE                                                  $5
    8    12      > RETURN                                                   !2
    9    13*     > RETURN                                                   null

End of function substr_count_array

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168.89 ms | 1402 KiB | 18 Q