3v4l.org

run code in 300+ PHP versions simultaneously
<?php $A = [3,45,67,8]; $B = [ 1 => [1,6,8], 2 => [5,67,3,4,5,66,6], 3 => [55,56,57,58], 4 => [45,80,81,82] ]; $result = []; foreach ($A as $needle) { if ($found = array_keys($B, $needle)) { // something qualified echo "Found: "; var_export($found); $result = array_merge($result, $found); // store the new key(s) $B = array_intersect_key($B, $found); // reduce the haystack } echo "Needle: $needle\n"; var_export($B); echo "\n--\n"; var_export($result); echo "\n----\n"; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 38
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 38
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 25
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 25
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
filename:       /in/h4LJ2
function name:  (null)
number of ops:  40
compiled vars:  !0 = $A, !1 = $B, !2 = $result, !3 = $needle, !4 = $found
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    3     1        ASSIGN                                                   !1, <array>
    9     2        ASSIGN                                                   !2, <array>
   10     3      > FE_RESET_R                                       $8      !0, ->38
          4    > > FE_FETCH_R                                               $8, !3, ->38
   11     5    >   INIT_FCALL                                               'array_keys'
          6        SEND_VAR                                                 !1
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $9      
          9        ASSIGN                                           ~10     !4, $9
         10      > JMPZ                                                     ~10, ->25
   12    11    >   ECHO                                                     'Found%3A+'
   13    12        INIT_FCALL                                               'var_export'
         13        SEND_VAR                                                 !4
         14        DO_ICALL                                                 
   14    15        INIT_FCALL                                               'array_merge'
         16        SEND_VAR                                                 !2
         17        SEND_VAR                                                 !4
         18        DO_ICALL                                         $12     
         19        ASSIGN                                                   !2, $12
   15    20        INIT_FCALL                                               'array_intersect_key'
         21        SEND_VAR                                                 !1
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $14     
         24        ASSIGN                                                   !1, $14
   17    25    >   ROPE_INIT                                     3  ~17     'Needle%3A+'
         26        ROPE_ADD                                      1  ~17     ~17, !3
         27        ROPE_END                                      2  ~16     ~17, '%0A'
         28        ECHO                                                     ~16
   18    29        INIT_FCALL                                               'var_export'
         30        SEND_VAR                                                 !1
         31        DO_ICALL                                                 
   19    32        ECHO                                                     '%0A--%0A'
   20    33        INIT_FCALL                                               'var_export'
         34        SEND_VAR                                                 !2
         35        DO_ICALL                                                 
   21    36        ECHO                                                     '%0A----%0A'
   10    37      > JMP                                                      ->4
         38    >   FE_FREE                                                  $8
   22    39      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.49 ms | 1400 KiB | 21 Q