3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = 'try replacing {foo} and {huh} and {bar} in text'; $data_array = [ 'foo' => 'fighters', 'bar' => 'snacks', ]; echo preg_replace_callback( '/{(\w+)}/', fn($m) => $data_array[$m[1]] ?? $m[0], $string );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2TmrM
function name:  (null)
number of ops:  11
compiled vars:  !0 = $string, !1 = $data_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'try+replacing+%7Bfoo%7D+and+%7Bhuh%7D+and+%7Bbar%7D+in+text'
    5     1        ASSIGN                                                   !1, <array>
   10     2        INIT_FCALL                                               'preg_replace_callback'
   11     3        SEND_VAL                                                 '%2F%7B%28%5Cw%2B%29%7D%2F'
   12     4        DECLARE_LAMBDA_FUNCTION                          ~4      [0]
          5        BIND_LEXICAL                                             ~4, !1
          6        SEND_VAL                                                 ~4
   13     7        SEND_VAR                                                 !0
   10     8        DO_ICALL                                         $5      
   13     9        ECHO                                                     $5
   14    10      > 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/2TmrM
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $m, !1 = $data_array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_DIM_R                                      ~2      !0, 1
          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 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.92 ms | 1010 KiB | 14 Q