3v4l.org

run code in 500+ PHP versions simultaneously
<?php $interesting_words = [ 'test' => [ 'number_of_occurances' => 0, 'connected_words' => [ 'TEST', 'TESTER', 'TESTING' ] ], 'foobar' => [ 'number_of_occurances' => 0, 'connected_words' => [ 'FOO', 'FOOBAR', 'BAR' ] ] ]; $str = 'Lorem ipsum TEST sit amet, consectetur TESTER elit. Sed in turpis dui. Maecenas venenatis FOOBAR facilisis. Quisque dictum, diam consequat mollis TESTING, orci tellus aliquet nisl, BAR molestie FOO augue at est. In TESTING vehicula lectus. Curabitur ac varius ligula. Pellentesque orci urdna.'; $str = preg_replace('/[\.\,]/i','',$str); $str = strtolower($str); $str_arr = explode(" ",$str); $str_occurance_counts = array_count_values($str_arr); foreach($interesting_words as $k=>&$v){ foreach($v['connected_words'] as $c=>$cVal){ $v['number_of_occurances'] += $str_occurance_counts[strtolower($cVal)]; } echo "Number of occurances for '$k': ".$v['number_of_occurances']."\n"; } print_r($interesting_words ); ?>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 19, Position 2 = 41
Branch analysis from position: 19
2 jumps found. (Code = 126) Position 1 = 20, Position 2 = 41
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 32
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 32
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 41
filename:       /in/l4kIq
function name:  (null)
number of ops:  46
compiled vars:  !0 = $interesting_words, !1 = $str, !2 = $str_arr, !3 = $str_occurance_counts, !4 = $v, !5 = $k, !6 = $cVal, !7 = $c
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                       !0, <array>
   20     1        ASSIGN                                                       !1, 'Lorem+ipsum+TEST+sit+amet%2C+consectetur+TESTER+elit.+Sed+in+turpis+dui.+Maecenas+venenatis+FOOBAR+facilisis.+Quisque+dictum%2C+diam+consequat+mollis+TESTING%2C+orci+tellus+aliquet+nisl%2C+BAR+molestie+FOO+augue+at+est.+In+TESTING+vehicula+lectus.+Curabitur+ac+varius+ligula.+Pellentesque+orci+urdna.'
   21     2        FRAMELESS_ICALL_3                preg_replace        ~10     '%2F%5B%5C.%5C%2C%5D%2Fi', ''
          3        OP_DATA                                                      !1
          4        ASSIGN                                                       !1, ~10
   22     5        INIT_FCALL                                                   'strtolower'
          6        SEND_VAR                                                     !1
          7        DO_ICALL                                             $12     
          8        ASSIGN                                                       !1, $12
   23     9        INIT_FCALL                                                   'explode'
         10        SEND_VAL                                                     '+'
         11        SEND_VAR                                                     !1
         12        DO_ICALL                                             $14     
         13        ASSIGN                                                       !2, $14
   24    14        INIT_FCALL                                                   'array_count_values'
         15        SEND_VAR                                                     !2
         16        DO_ICALL                                             $16     
         17        ASSIGN                                                       !3, $16
   25    18      > FE_RESET_RW                                          $18     !0, ->41
         19    > > FE_FETCH_RW                                          ~19     $18, !4, ->41
         20    >   ASSIGN                                                       !5, ~19
   26    21        FETCH_DIM_R                                          ~21     !4, 'connected_words'
         22      > FE_RESET_R                                           $22     ~21, ->32
         23    > > FE_FETCH_R                                           ~23     $22, !6, ->32
         24    >   ASSIGN                                                       !7, ~23
   27    25        INIT_FCALL                                                   'strtolower'
         26        SEND_VAR                                                     !6
         27        DO_ICALL                                             $26     
         28        FETCH_DIM_R                                          ~27     !3, $26
         29        ASSIGN_DIM_OP                    +=               1          !4, 'number_of_occurances'
         30        OP_DATA                                                      ~27
   26    31      > JMP                                                          ->23
         32    >   FE_FREE                                                      $22
   29    33        ROPE_INIT                                         3  ~29     'Number+of+occurances+for+%27'
         34        ROPE_ADD                                          1  ~29     ~29, !5
         35        ROPE_END                                          2  ~28     ~29, '%27%3A+'
         36        FETCH_DIM_R                                          ~31     !4, 'number_of_occurances'
         37        CONCAT                                               ~32     ~28, ~31
         38        CONCAT                                               ~33     ~32, '%0A'
         39        ECHO                                                         ~33
   25    40      > JMP                                                          ->19
         41    >   FE_FREE                                                      $18
   31    42        INIT_FCALL                                                   'print_r'
         43        SEND_VAR                                                     !0
         44        DO_ICALL                                                     
   32    45      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
166.79 ms | 3520 KiB | 17 Q