3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myVar = 'essa pizza é muito gostosa, gostosa, gostosa, gosto'; $myWords = [ ['sabor', 'gosto', 'delicia'], ['saborosa', 'gostosa', 'deliciosa'], ]; $grouped = []; $flipped = []; foreach ($myWords as $row) { $grouped[] = '(' . implode('|', $row) . ')'; $flipped[] = array_flip($row); } $pattern = '/\b(?:' . implode('|', $grouped) . ')\b/'; var_export( preg_replace_callback( $pattern, function($m) use ($flipped) { array_shift($m); foreach ($m as $i => $captured) { if ($captured) { unset($flipped[$i][$captured]); return array_rand($flipped[$i]); } } }, $myVar ) );
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/XkPSp
function name:  (null)
number of ops:  39
compiled vars:  !0 = $myVar, !1 = $myWords, !2 = $grouped, !3 = $flipped, !4 = $row, !5 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'essa+pizza+%C3%A9+muito+gostosa%2C+gostosa%2C+gostosa%2C+gosto'
    5     1        ASSIGN                                                   !1, <array>
   10     2        ASSIGN                                                   !2, <array>
   11     3        ASSIGN                                                   !3, <array>
   12     4      > FE_RESET_R                                       $10     !1, ->20
          5    > > FE_FETCH_R                                               $10, !4, ->20
   13     6    >   INIT_FCALL                                               'implode'
          7        SEND_VAL                                                 '%7C'
          8        SEND_VAR                                                 !4
          9        DO_ICALL                                         $12     
         10        CONCAT                                           ~13     '%28', $12
         11        CONCAT                                           ~14     ~13, '%29'
         12        ASSIGN_DIM                                               !2
         13        OP_DATA                                                  ~14
   14    14        INIT_FCALL                                               'array_flip'
         15        SEND_VAR                                                 !4
         16        DO_ICALL                                         $16     
         17        ASSIGN_DIM                                               !3
         18        OP_DATA                                                  $16
   12    19      > JMP                                                      ->5
         20    >   FE_FREE                                                  $10
   16    21        INIT_FCALL                                               'implode'
         22        SEND_VAL                                                 '%7C'
         23        SEND_VAR                                                 !2
         24        DO_ICALL                                         $17     
         25        CONCAT                                           ~18     '%2F%5Cb%28%3F%3A', $17
         26        CONCAT                                           ~19     ~18, '%29%5Cb%2F'
         27        ASSIGN                                                   !5, ~19
   18    28        INIT_FCALL                                               'var_export'
   19    29        INIT_FCALL                                               'preg_replace_callback'
   20    30        SEND_VAR                                                 !5
   21    31        DECLARE_LAMBDA_FUNCTION                          ~21     [0]
         32        BIND_LEXICAL                                             ~21, !3
   29    33        SEND_VAL                                                 ~21
   30    34        SEND_VAR                                                 !0
   19    35        DO_ICALL                                         $22     
   30    36        SEND_VAR                                                 $22
   18    37        DO_ICALL                                                 
   32    38      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 6, Position 2 = 18
Branch analysis from position: 6
2 jumps found. (Code = 78) Position 1 = 7, Position 2 = 18
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 17
Branch analysis from position: 9
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
filename:       /in/XkPSp
function name:  {closure}
number of ops:  20
compiled vars:  !0 = $m, !1 = $flipped, !2 = $captured, !3 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   22     2        INIT_FCALL                                               'array_shift'
          3        SEND_REF                                                 !0
          4        DO_ICALL                                                 
   23     5      > FE_RESET_R                                       $5      !0, ->18
          6    > > FE_FETCH_R                                       ~6      $5, !2, ->18
          7    >   ASSIGN                                                   !3, ~6
   24     8      > JMPZ                                                     !2, ->17
   25     9    >   FETCH_DIM_UNSET                                  $8      !1, !3
         10        UNSET_DIM                                                $8, !2
   26    11        INIT_FCALL                                               'array_rand'
         12        FETCH_DIM_R                                      ~9      !1, !3
         13        SEND_VAL                                                 ~9
         14        DO_ICALL                                         $10     
         15        FE_FREE                                                  $5
         16      > RETURN                                                   $10
   23    17    > > JMP                                                      ->6
         18    >   FE_FREE                                                  $5
   29    19      > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.75 ms | 1015 KiB | 19 Q