3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sentence = 'My New Scooter is very Good'; $array = [ "Good Scooter", "lovely very Good Scooter", "Scooter is very Good and New", "Scooter is very Good and its My New Scooter" ]; $words = explode(' ', $sentence); $winner = ['index' => false, 'count' => 0 ]; foreach ($array as $k => $v) { $common = array_intersect($words, explode(' ', $v)); if ( $winner['count'] < count($common) ) $winner = ['index' => $k, 'count' => count($common)]; if ( $winner['count'] === count($words) ) break; } var_dump($winner);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 34
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 34
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 28
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 33
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 34
Branch analysis from position: 34
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 28
Branch analysis from position: 34
Branch analysis from position: 34
filename:       /in/HLdDJ
function name:  (null)
number of ops:  39
compiled vars:  !0 = $sentence, !1 = $array, !2 = $words, !3 = $winner, !4 = $v, !5 = $k, !6 = $common
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'My+New+Scooter+is+very+Good'
    5     1        ASSIGN                                                   !1, <array>
   12     2        INIT_FCALL                                               'explode'
          3        SEND_VAL                                                 '+'
          4        SEND_VAR                                                 !0
          5        DO_ICALL                                         $9      
          6        ASSIGN                                                   !2, $9
   14     7        ASSIGN                                                   !3, <array>
   16     8      > FE_RESET_R                                       $12     !1, ->34
          9    > > FE_FETCH_R                                       ~13     $12, !4, ->34
         10    >   ASSIGN                                                   !5, ~13
   17    11        INIT_FCALL                                               'array_intersect'
         12        SEND_VAR                                                 !2
         13        INIT_FCALL                                               'explode'
         14        SEND_VAL                                                 '+'
         15        SEND_VAR                                                 !4
         16        DO_ICALL                                         $15     
         17        SEND_VAR                                                 $15
         18        DO_ICALL                                         $16     
         19        ASSIGN                                                   !6, $16
   19    20        FETCH_DIM_R                                      ~18     !3, 'count'
         21        COUNT                                            ~19     !6
         22        IS_SMALLER                                               ~18, ~19
         23      > JMPZ                                                     ~20, ->28
   20    24    >   INIT_ARRAY                                       ~21     !5, 'index'
         25        COUNT                                            ~22     !6
         26        ADD_ARRAY_ELEMENT                                ~21     ~22, 'count'
         27        ASSIGN                                                   !3, ~21
   22    28    >   FETCH_DIM_R                                      ~24     !3, 'count'
         29        COUNT                                            ~25     !2
         30        IS_IDENTICAL                                             ~24, ~25
         31      > JMPZ                                                     ~26, ->33
   23    32    > > JMP                                                      ->34
   16    33    > > JMP                                                      ->9
         34    >   FE_FREE                                                  $12
   26    35        INIT_FCALL                                               'var_dump'
         36        SEND_VAR                                                 !3
         37        DO_ICALL                                                 
         38      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
288.01 ms | 1017 KiB | 16 Q