3v4l.org

run code in 300+ PHP versions simultaneously
<?php $body = "I love My Dog. I love My cat. What a cat."; $count = my_substr_count($body, "My cat"); function my_substr_count( $body, $needle) { $count = [ $needle => substr_count( $body, $needle) ]; $tokens = array_map( function( $el) { return '\b' . $el . '\b'; }, explode( ' ', $needle)); foreach( $tokens as $token) $count[$token] = substr_count( $body, $token); return $count; } print_r( $count);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fg4pK
function name:  (null)
number of ops:  10
compiled vars:  !0 = $body, !1 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, 'I+love+My+Dog.+I+love+My+cat.+What+a+cat.'
    3     1        INIT_FCALL_BY_NAME                                       'my_substr_count'
          2        SEND_VAR_EX                                              !0
          3        SEND_VAL_EX                                              'My+cat'
          4        DO_FCALL                                      0  $3      
          5        ASSIGN                                                   !1, $3
   15     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function my_substr_count:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 27
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 27
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 27
filename:       /in/fg4pK
function name:  my_substr_count
number of ops:  30
compiled vars:  !0 = $body, !1 = $needle, !2 = $count, !3 = $tokens, !4 = $token
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    6     2        INIT_FCALL                                               'substr_count'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $5      
          6        INIT_ARRAY                                       ~6      $5, !1
          7        ASSIGN                                                   !2, ~6
    8     8        INIT_FCALL                                               'array_map'
          9        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Ffg4pK%3A8%240'
         10        SEND_VAL                                                 ~8
         11        INIT_FCALL                                               'explode'
         12        SEND_VAL                                                 '+'
         13        SEND_VAR                                                 !1
         14        DO_ICALL                                         $9      
         15        SEND_VAR                                                 $9
         16        DO_ICALL                                         $10     
         17        ASSIGN                                                   !3, $10
    9    18      > FE_RESET_R                                       $12     !3, ->27
         19    > > FE_FETCH_R                                               $12, !4, ->27
   10    20    >   INIT_FCALL                                               'substr_count'
         21        SEND_VAR                                                 !0
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $14     
         24        ASSIGN_DIM                                               !2, !4
         25        OP_DATA                                                  $14
    9    26      > JMP                                                      ->19
         27    >   FE_FREE                                                  $12
   12    28      > RETURN                                                   !2
   13    29*     > RETURN                                                   null

End of function my_substr_count

Function %00%7Bclosure%7D%2Fin%2Ffg4pK%3A8%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/fg4pK
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $el
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        CONCAT                                           ~1      '%5Cb', !0
          2        CONCAT                                           ~2      ~1, '%5Cb'
          3      > RETURN                                                   ~2
          4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Ffg4pK%3A8%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.17 ms | 1400 KiB | 21 Q