3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = ['word', 'chord', 'tech', 'care', 'kek', 'lol', 'wild', 'regex']; $arr2 = ['ord', 'ek', 'ol', 'ld', 'gex', 'ss']; $keys=[]; foreach($arr2 as $val){ $matches = preg_grep("/.+" . preg_quote($val) . "/", $arr1); $keys = array_merge($keys, array_keys($matches)); // save keys of matched words foreach($matches as $key => $m) $new[$val][] = str_replace($val, "_$val", $arr1[$key]); } $new['unmatched'] = array_diff_key($arr1, array_flip($keys)); // add unmatched words var_dump($new);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 40
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 40
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 38
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 38
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 38
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 38
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
filename:       /in/gfUea
function name:  (null)
number of ops:  54
compiled vars:  !0 = $arr1, !1 = $arr2, !2 = $keys, !3 = $val, !4 = $matches, !5 = $m, !6 = $key, !7 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
    7     3      > FE_RESET_R                                       $11     !1, ->40
          4    > > FE_FETCH_R                                               $11, !3, ->40
    8     5    >   INIT_FCALL                                               'preg_grep'
          6        INIT_FCALL                                               'preg_quote'
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $12     
          9        CONCAT                                           ~13     '%2F.%2B', $12
         10        CONCAT                                           ~14     ~13, '%2F'
         11        SEND_VAL                                                 ~14
         12        SEND_VAR                                                 !0
         13        DO_ICALL                                         $15     
         14        ASSIGN                                                   !4, $15
    9    15        INIT_FCALL                                               'array_merge'
         16        SEND_VAR                                                 !2
         17        INIT_FCALL                                               'array_keys'
         18        SEND_VAR                                                 !4
         19        DO_ICALL                                         $17     
         20        SEND_VAR                                                 $17
         21        DO_ICALL                                         $18     
         22        ASSIGN                                                   !2, $18
   10    23      > FE_RESET_R                                       $20     !4, ->38
         24    > > FE_FETCH_R                                       ~21     $20, !5, ->38
         25    >   ASSIGN                                                   !6, ~21
         26        INIT_FCALL                                               'str_replace'
         27        SEND_VAR                                                 !3
         28        NOP                                                      
         29        FAST_CONCAT                                      ~25     '_', !3
         30        SEND_VAL                                                 ~25
         31        FETCH_DIM_R                                      ~26     !0, !6
         32        SEND_VAL                                                 ~26
         33        DO_ICALL                                         $27     
         34        FETCH_DIM_W                                      $23     !7, !3
         35        ASSIGN_DIM                                               $23
         36        OP_DATA                                                  $27
         37      > JMP                                                      ->24
         38    >   FE_FREE                                                  $20
    7    39      > JMP                                                      ->4
         40    >   FE_FREE                                                  $11
   12    41        INIT_FCALL                                               'array_diff_key'
         42        SEND_VAR                                                 !0
         43        INIT_FCALL                                               'array_flip'
         44        SEND_VAR                                                 !2
         45        DO_ICALL                                         $29     
         46        SEND_VAR                                                 $29
         47        DO_ICALL                                         $30     
         48        ASSIGN_DIM                                               !7, 'unmatched'
         49        OP_DATA                                                  $30
   13    50        INIT_FCALL                                               'var_dump'
         51        SEND_VAR                                                 !7
         52        DO_ICALL                                                 
         53      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.19 ms | 1400 KiB | 29 Q