3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = array( 'def9', 'abc7', 'cbd4' ); $b = array('r1' => '/abc\d/', 'b2' => '/cbd\d/', 'f5' => '/def\d/'); $result = array(); // Store the result $iloop = 0; // Use to match corresponding element key in $a; $matches = array(); foreach($b AS $key => $preg) { if (preg_match($preg, $a[$iloop++], $matches)) { $result[$key] = $matches[0]; } } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 20
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 19
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 19
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/HRQuH
function name:  (null)
number of ops:  25
compiled vars:  !0 = $a, !1 = $b, !2 = $result, !3 = $iloop, !4 = $matches, !5 = $preg, !6 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
    7     2        ASSIGN                                                   !2, <array>
    9     3        ASSIGN                                                   !3, 0
   11     4        ASSIGN                                                   !4, <array>
   13     5      > FE_RESET_R                                       $12     !1, ->20
          6    > > FE_FETCH_R                                       ~13     $12, !5, ->20
          7    >   ASSIGN                                                   !6, ~13
   14     8        INIT_FCALL                                               'preg_match'
          9        SEND_VAR                                                 !5
         10        POST_INC                                         ~15     !3
         11        FETCH_DIM_R                                      ~16     !0, ~15
         12        SEND_VAL                                                 ~16
         13        SEND_REF                                                 !4
         14        DO_ICALL                                         $17     
         15      > JMPZ                                                     $17, ->19
   15    16    >   FETCH_DIM_R                                      ~19     !4, 0
         17        ASSIGN_DIM                                               !2, !6
         18        OP_DATA                                                  ~19
   13    19    > > JMP                                                      ->6
         20    >   FE_FREE                                                  $12
   19    21        INIT_FCALL                                               'print_r'
         22        SEND_VAR                                                 !2
         23        DO_ICALL                                                 
         24      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
153.38 ms | 1387 KiB | 17 Q