3v4l.org

run code in 500+ PHP versions simultaneously
<?php $articleText = <<<TEXT Some article text Triple id: {gameid 45735 76352 87262}. Do not honor {gameid 12345 67890} because contains exactly 2 game ids! unknown id: {gameid 66666} can't replace it! Found single id: {gameid 76352} finished the article TEXT; $gamesLookup = [ 45735 => 'Pac-man', 76352 => 'Donkey Kong', 87262 => 'Rampage' ]; echo preg_replace_callback( '~{gameid (\d{5})(?: (\d{5}) (\d{5}))?}~', function ($m) use ($gamesLookup) { echo 'm = ' . var_export($m, true) . "\n---\n"; return 'Game Name(s): ' . strtr(implode(', ', array_slice($m, 1)), $gamesLookup); }, $articleText );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/cuIim
function name:  (null)
number of ops:  11
compiled vars:  !0 = $articleText, !1 = $gamesLookup
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'Some+article+text%0ATriple+id%3A+%7Bgameid+45735+76352+87262%7D.%0ADo+not+honor+%7Bgameid+12345+67890%7D+because+contains+exactly+2+game+ids%21%0Aunknown+id%3A+%7Bgameid+66666%7D+can%27t+replace+it%21%0AFound+single+id%3A+%7Bgameid+76352%7D%0Afinished+the+article'
   12     1        ASSIGN                                                       !1, <array>
   18     2        INIT_FCALL                                                   'preg_replace_callback'
   19     3        SEND_VAL                                                     '%7E%7Bgameid+%28%5Cd%7B5%7D%29%28%3F%3A+%28%5Cd%7B5%7D%29+%28%5Cd%7B5%7D%29%29%3F%7D%7E'
   20     4        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          5        BIND_LEXICAL                                                 ~4, !1
   23     6        SEND_VAL                                                     ~4
   24     7        SEND_VAR                                                     !0
   18     8        DO_ICALL                                             $5      
   24     9        ECHO                                                         $5
   25    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/cuIim
function name:  {closure:/in/cuIim:20}
number of ops:  18
compiled vars:  !0 = $m, !1 = $gamesLookup
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   20     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   21     2        INIT_FCALL                                                   'var_export'
          3        SEND_VAR                                                     !0
          4        SEND_VAL                                                     <true>
          5        DO_ICALL                                             $2      
          6        CONCAT                                               ~3      'm+%3D+', $2
          7        CONCAT                                               ~4      ~3, '%0A---%0A'
          8        ECHO                                                         ~4
   22     9        INIT_FCALL                                                   'array_slice'
         10        SEND_VAR                                                     !0
         11        SEND_VAL                                                     1
         12        DO_ICALL                                             $5      
         13        FRAMELESS_ICALL_2                implode             ~6      '%2C+', $5
         14        FRAMELESS_ICALL_2                strtr               ~7      ~6, !1
         15        CONCAT                                               ~8      'Game+Name%28s%29%3A+', ~7
         16      > RETURN                                                       ~8
   23    17*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
130.89 ms | 481 KiB | 10 Q