3v4l.org

run code in 300+ PHP versions simultaneously
<?php $origin = ['value1', 'value2', 'value3', '-2', '2', '22']; $replace_map = [ 'value1' => 'replace1', 'value2' => 'replace2', 'value8' => 'replace8', 2 => 77 ]; var_export( preg_replace_callback( '~^-?\K.*$~', function ($m) use ($replace_map) { return $replace_map[$m[0]] ?? $m[0]; }, $origin ) ); var_export( preg_replace_callback('~^-?\K.*$~', fn($m)=> $replace_map[$m[0]] ?? $m[0], $origin) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uSNDj
function name:  (null)
number of ops:  23
compiled vars:  !0 = $origin, !1 = $replace_map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    5     1        ASSIGN                                                   !1, <array>
   12     2        INIT_FCALL                                               'var_export'
   13     3        INIT_FCALL                                               'preg_replace_callback'
   14     4        SEND_VAL                                                 '%7E%5E-%3F%5CK.%2A%24%7E'
   15     5        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          6        BIND_LEXICAL                                             ~4, !1
   17     7        SEND_VAL                                                 ~4
   18     8        SEND_VAR                                                 !0
   13     9        DO_ICALL                                         $5      
   18    10        SEND_VAR                                                 $5
   12    11        DO_ICALL                                                 
   22    12        INIT_FCALL                                               'var_export'
   23    13        INIT_FCALL                                               'preg_replace_callback'
         14        SEND_VAL                                                 '%7E%5E-%3F%5CK.%2A%24%7E'
         15        DECLARE_LAMBDA_FUNCTION                          ~7      [1]
         16        BIND_LEXICAL                                             ~7, !1
         17        SEND_VAL                                                 ~7
         18        SEND_VAR                                                 !0
         19        DO_ICALL                                         $8      
         20        SEND_VAR                                                 $8
   22    21        DO_ICALL                                                 
   24    22      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uSNDj
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $m, !1 = $replace_map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   16     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
   17     8*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/uSNDj
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $m, !1 = $replace_map
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     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 Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.6 ms | 1006 KiB | 15 Q