3v4l.org

run code in 300+ PHP versions simultaneously
<?php $str = ' I love [123] and [124] at (456). I hate [234] and [235] at (123).'; $table1Col1=["123" => "a", "124" => "b", "234" => "c", "235" => "d"]; $table1Col2 = ["456" => "XX", "123" => "ZZ"]; $pattern = "/\[(\d+)]|\((\d+)\)/"; $result = preg_replace_callback($pattern, function($match) use ($table1Col1, $table1Col2) { return sprintf('<a title="%s">%s</a>', array_key_exists(2, $match) ? $table1Col2[$match[2]] : $table1Col1[$match[1]] , $match[0] ); }, $str); echo $result;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ijbGY
function name:  (null)
number of ops:  15
compiled vars:  !0 = $str, !1 = $table1Col1, !2 = $table1Col2, !3 = $pattern, !4 = $result
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '+I+love+%5B123%5D+and+%5B124%5D+at+%28456%29.+I+hate+%5B234%5D+and+%5B235%5D+at+%28123%29.'
    4     1        ASSIGN                                                   !1, <array>
    5     2        ASSIGN                                                   !2, <array>
    6     3        ASSIGN                                                   !3, '%2F%5C%5B%28%5Cd%2B%29%5D%7C%5C%28%28%5Cd%2B%29%5C%29%2F'
    8     4        INIT_FCALL                                               'preg_replace_callback'
          5        SEND_VAR                                                 !3
          6        DECLARE_LAMBDA_FUNCTION                          ~9      [0]
          7        BIND_LEXICAL                                             ~9, !1
          8        BIND_LEXICAL                                             ~9, !2
   13     9        SEND_VAL                                                 ~9
         10        SEND_VAR                                                 !0
    8    11        DO_ICALL                                         $10     
         12        ASSIGN                                                   !4, $10
   15    13        ECHO                                                     !4
   16    14      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 7, Position 2 = 11
Branch analysis from position: 7
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/ijbGY
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $match, !1 = $table1Col1, !2 = $table1Col2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
    9     3        INIT_FCALL                                               'sprintf'
          4        SEND_VAL                                                 '%3Ca+title%3D%22%25s%22%3E%25s%3C%2Fa%3E'
   10     5        ARRAY_KEY_EXISTS                                         2, !0
          6      > JMPZ                                                     ~3, ->11
          7    >   FETCH_DIM_R                                      ~4      !0, 2
          8        FETCH_DIM_R                                      ~5      !2, ~4
          9        QM_ASSIGN                                        ~6      ~5
         10      > JMP                                                      ->14
         11    >   FETCH_DIM_R                                      ~7      !0, 1
         12        FETCH_DIM_R                                      ~8      !1, ~7
         13        QM_ASSIGN                                        ~6      ~8
         14    >   SEND_VAL                                                 ~6
   11    15        FETCH_DIM_R                                      ~9      !0, 0
         16        SEND_VAL                                                 ~9
    9    17        DO_ICALL                                         $10     
   11    18      > RETURN                                                   $10
   13    19*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
275.83 ms | 1016 KiB | 15 Q