3v4l.org

run code in 300+ 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 = 22, Position 2 = 44
Branch analysis from position: 22
2 jumps found. (Code = 126) Position 1 = 23, Position 2 = 44
Branch analysis from position: 23
2 jumps found. (Code = 77) Position 1 = 26, Position 2 = 35
Branch analysis from position: 26
2 jumps found. (Code = 78) Position 1 = 27, Position 2 = 35
Branch analysis from position: 27
1 jumps found. (Code = 42) Position 1 = 26
Branch analysis from position: 26
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 22
Branch analysis from position: 22
Branch analysis from position: 35
Branch analysis from position: 44
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
filename:       /in/l4kIq
function name:  (null)
number of ops:  49
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        INIT_FCALL                                               'preg_replace'
          3        SEND_VAL                                                 '%2F%5B%5C.%5C%2C%5D%2Fi'
          4        SEND_VAL                                                 ''
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $10     
          7        ASSIGN                                                   !1, $10
   22     8        INIT_FCALL                                               'strtolower'
          9        SEND_VAR                                                 !1
         10        DO_ICALL                                         $12     
         11        ASSIGN                                                   !1, $12
   23    12        INIT_FCALL                                               'explode'
         13        SEND_VAL                                                 '+'
         14        SEND_VAR                                                 !1
         15        DO_ICALL                                         $14     
         16        ASSIGN                                                   !2, $14
   24    17        INIT_FCALL                                               'array_count_values'
         18        SEND_VAR                                                 !2
         19        DO_ICALL                                         $16     
         20        ASSIGN                                                   !3, $16
   25    21      > FE_RESET_RW                                      $18     !0, ->44
         22    > > FE_FETCH_RW                                      ~19     $18, !4, ->44
         23    >   ASSIGN                                                   !5, ~19
   26    24        FETCH_DIM_R                                      ~21     !4, 'connected_words'
         25      > FE_RESET_R                                       $22     ~21, ->35
         26    > > FE_FETCH_R                                       ~23     $22, !6, ->35
         27    >   ASSIGN                                                   !7, ~23
   27    28        INIT_FCALL                                               'strtolower'
         29        SEND_VAR                                                 !6
         30        DO_ICALL                                         $26     
         31        FETCH_DIM_R                                      ~27     !3, $26
         32        ASSIGN_DIM_OP                +=               1          !4, 'number_of_occurances'
         33        OP_DATA                                                  ~27
   26    34      > JMP                                                      ->26
         35    >   FE_FREE                                                  $22
   29    36        ROPE_INIT                                     3  ~29     'Number+of+occurances+for+%27'
         37        ROPE_ADD                                      1  ~29     ~29, !5
         38        ROPE_END                                      2  ~28     ~29, '%27%3A+'
         39        FETCH_DIM_R                                      ~31     !4, 'number_of_occurances'
         40        CONCAT                                           ~32     ~28, ~31
         41        CONCAT                                           ~33     ~32, '%0A'
         42        ECHO                                                     ~33
   25    43      > JMP                                                      ->22
         44    >   FE_FREE                                                  $18
   31    45        INIT_FCALL                                               'print_r'
         46        SEND_VAR                                                 !0
         47        DO_ICALL                                                 
   32    48      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.07 ms | 1400 KiB | 23 Q