3v4l.org

run code in 300+ PHP versions simultaneously
<?php $masks = ['1224*', '543*', '321*', '12245*', '5*', '122488*']; sort($masks); $needle = rtrim(array_shift($masks), '*'); $keep[] = $needle; foreach ($masks as $mask) { if (strpos($mask, $needle) !== 0) { $needle = rtrim($mask, '*'); $keep[] = $needle; } } // now $keep only contains: ['1224', '321', '5'] $numbers = ['122456789', '123456788', '321876543234567', '55555555555555555', '987654321']; var_export( preg_grep('~^(?:' . implode('|', $keep) . ')~', $numbers) );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 15, Position 2 = 30
Branch analysis from position: 15
2 jumps found. (Code = 78) Position 1 = 16, Position 2 = 30
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 29
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 15
Branch analysis from position: 15
Branch analysis from position: 29
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/uLOKf
function name:  (null)
number of ops:  46
compiled vars:  !0 = $masks, !1 = $needle, !2 = $keep, !3 = $mask, !4 = $numbers
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        INIT_FCALL                                               'sort'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                                 
    5     4        INIT_FCALL                                               'rtrim'
          5        INIT_FCALL                                               'array_shift'
          6        SEND_REF                                                 !0
          7        DO_ICALL                                         $7      
          8        SEND_VAR                                                 $7
          9        SEND_VAL                                                 '%2A'
         10        DO_ICALL                                         $8      
         11        ASSIGN                                                   !1, $8
    6    12        ASSIGN_DIM                                               !2
         13        OP_DATA                                                  !1
    7    14      > FE_RESET_R                                       $11     !0, ->30
         15    > > FE_FETCH_R                                               $11, !3, ->30
    8    16    >   INIT_FCALL                                               'strpos'
         17        SEND_VAR                                                 !3
         18        SEND_VAR                                                 !1
         19        DO_ICALL                                         $12     
         20        IS_NOT_IDENTICAL                                         $12, 0
         21      > JMPZ                                                     ~13, ->29
    9    22    >   INIT_FCALL                                               'rtrim'
         23        SEND_VAR                                                 !3
         24        SEND_VAL                                                 '%2A'
         25        DO_ICALL                                         $14     
         26        ASSIGN                                                   !1, $14
   10    27        ASSIGN_DIM                                               !2
         28        OP_DATA                                                  !1
    7    29    > > JMP                                                      ->15
         30    >   FE_FREE                                                  $11
   15    31        ASSIGN                                                   !4, <array>
   17    32        INIT_FCALL                                               'var_export'
   18    33        INIT_FCALL                                               'preg_grep'
         34        INIT_FCALL                                               'implode'
         35        SEND_VAL                                                 '%7C'
         36        SEND_VAR                                                 !2
         37        DO_ICALL                                         $18     
         38        CONCAT                                           ~19     '%7E%5E%28%3F%3A', $18
         39        CONCAT                                           ~20     ~19, '%29%7E'
         40        SEND_VAL                                                 ~20
         41        SEND_VAR                                                 !4
         42        DO_ICALL                                         $21     
         43        SEND_VAR                                                 $21
   17    44        DO_ICALL                                                 
   19    45      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
235.17 ms | 1009 KiB | 20 Q