3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = 'gamer thing gamer games test games'; $pattern = '/\b(?<keyword>gamer|games)\b/'; // We'll append to this array after we use a given keyword $usedKeywords = []; $finalString = preg_replace_callback( $pattern, // Remember to capture the array by-ref static function (array $matches) use (&$usedKeywords) { $thisKeyword = $matches['keyword']; if (in_array($thisKeyword, $usedKeywords, true)) { return $thisKeyword; } $usedKeywords[] = $thisKeyword; // Do your replacement here return '~'.$thisKeyword.'~'; }, $string ); print_r($finalString);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j40Oq
function name:  (null)
number of ops:  15
compiled vars:  !0 = $string, !1 = $pattern, !2 = $usedKeywords, !3 = $finalString
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'gamer+thing+gamer+games+test+games'
    4     1        ASSIGN                                                       !1, '%2F%5Cb%28%3F%3Ckeyword%3Egamer%7Cgames%29%5Cb%2F'
    7     2        ASSIGN                                                       !2, <array>
    8     3        INIT_FCALL                                                   'preg_replace_callback'
    9     4        SEND_VAR                                                     !1
   12     5        DECLARE_LAMBDA_FUNCTION                              ~7      [0]
          6        BIND_LEXICAL                                                 ~7, !2
   23     7        SEND_VAL                                                     ~7
   24     8        SEND_VAR                                                     !0
    8     9        DO_ICALL                                             $8      
         10        ASSIGN                                                       !3, $8
   27    11        INIT_FCALL                                                   'print_r'
         12        SEND_VAR                                                     !3
         13        DO_ICALL                                                     
         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 = 8
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/j40Oq
function name:  {closure:/in/j40Oq:12}
number of ops:  14
compiled vars:  !0 = $matches, !1 = $usedKeywords, !2 = $thisKeyword
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   12     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
   13     2        FETCH_DIM_R                                          ~3      !0, 'keyword'
          3        ASSIGN                                                       !2, ~3
   14     4        FRAMELESS_ICALL_3                in_array            ~5      !2, !1
          5        OP_DATA                                                      <true>
          6      > JMPZ                                                         ~5, ->8
   15     7    > > RETURN                                                       !2
   18     8    >   ASSIGN_DIM                                                   !1
          9        OP_DATA                                                      !2
   21    10        CONCAT                                               ~7      '%7E', !2
         11        CONCAT                                               ~8      ~7, '%7E'
         12      > RETURN                                                       ~8
   23    13*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
187.37 ms | 2026 KiB | 15 Q