3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'hello w1 w2 w12 new1 new12 new2'; $map = [ 'w1' => 'new1', 'w2' => 'new2', 'new1' => 'w1', 'new2' => 'w2', ]; $subpattern = implode('|', array_map('preg_quote', array_keys($map))); echo preg_replace_callback( '#\b(?:' . $subpattern . ')\b#u', fn($m) => $map[$m[0]] ?? $m[0], $string );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aoeor
function name:  (null)
number of ops:  25
compiled vars:  !0 = $string, !1 = $map, !2 = $subpattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'hello+w1+w2+w12+new1+new12+new2'
    5     1        ASSIGN                                                   !1, <array>
   12     2        INIT_FCALL                                               'implode'
          3        SEND_VAL                                                 '%7C'
          4        INIT_FCALL                                               'array_map'
          5        SEND_VAL                                                 'preg_quote'
          6        INIT_FCALL                                               'array_keys'
          7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $5      
          9        SEND_VAR                                                 $5
         10        DO_ICALL                                         $6      
         11        SEND_VAR                                                 $6
         12        DO_ICALL                                         $7      
         13        ASSIGN                                                   !2, $7
   14    14        INIT_FCALL                                               'preg_replace_callback'
   15    15        CONCAT                                           ~9      '%23%5Cb%28%3F%3A', !2
         16        CONCAT                                           ~10     ~9, '%29%5Cb%23u'
         17        SEND_VAL                                                 ~10
   16    18        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2Faoeor%3A16%240'
         19        BIND_LEXICAL                                             ~11, !1
         20        SEND_VAL                                                 ~11
   17    21        SEND_VAR                                                 !0
         22        DO_ICALL                                         $12     
         23        ECHO                                                     $12
   18    24      > RETURN                                                   1

Function %00%7Bclosure%7D%2Fin%2Faoeor%3A16%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/aoeor
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $m, !1 = $map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_DIM_R                                      ~2      !0, 0
          3        FETCH_DIM_IS                                     ~3      !1, ~2
          4        COALESCE                                         ~4      ~3
          5        FETCH_DIM_R                                      ~5      !0, 0
          6        QM_ASSIGN                                        ~4      ~5
          7      > RETURN                                                   ~4
          8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2Faoeor%3A16%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.73 ms | 1401 KiB | 21 Q