3v4l.org

run code in 300+ PHP versions simultaneously
<?php $sentence = '{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}'; function sentence_spinning($str) { do { $str = preg_replace_callback('#\{([^{}]*)\}#', function($matches) { return explode('|', $matches[1])[mt_rand(0, substr_count($matches[1], '|'))]; }, $str, -1, $count); } while ($count !== 0); return $str; } echo $sentence, PHP_EOL, sentence_spinning($sentence);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J5ua1
function name:  (null)
number of ops:  8
compiled vars:  !0 = $sentence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%7BPlease%7CJust%7D+make+this+%7Bcool%7Cawesome%7Crandom%7D+test+sentence+%7Brotate+%7Bquickly%7Cfast%7D+and+random%7Cspin+and+be+random%7D'
   18     1        ECHO                                                     !0
          2        ECHO                                                     '%0A'
          3        INIT_FCALL                                               'sentence_spinning'
          4        SEND_VAR                                                 !0
          5        DO_FCALL                                      0  $2      
          6        ECHO                                                     $2
          7      > RETURN                                                   1

Function sentence_spinning:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 1
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 1
filename:       /in/J5ua1
function name:  sentence_spinning
number of ops:  14
compiled vars:  !0 = $str, !1 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    9     1    >   INIT_FCALL                                               'preg_replace_callback'
          2        SEND_VAL                                                 '%23%5C%7B%28%5B%5E%7B%7D%5D%2A%29%5C%7D%23'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FJ5ua1%3A9%240'
   12     4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 -1
          7        SEND_REF                                                 !1
          8        DO_ICALL                                         $3      
    9     9        ASSIGN                                                   !0, $3
   13    10        IS_NOT_IDENTICAL                                         !1, 0
         11      > JMPNZ                                                    ~5, ->1
   15    12    > > RETURN                                                   !0
   16    13*     > RETURN                                                   null

End of function sentence_spinning

Function %00%7Bclosure%7D%2Fin%2FJ5ua1%3A9%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/J5ua1
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   RECV                                             !0      
   11     1        INIT_FCALL                                               'explode'
          2        SEND_VAL                                                 '%7C'
          3        FETCH_DIM_R                                      ~1      !0, 1
          4        SEND_VAL                                                 ~1
          5        DO_ICALL                                         $2      
          6        INIT_FCALL                                               'mt_rand'
          7        SEND_VAL                                                 0
          8        INIT_FCALL                                               'substr_count'
          9        FETCH_DIM_R                                      ~3      !0, 1
         10        SEND_VAL                                                 ~3
         11        SEND_VAL                                                 '%7C'
         12        DO_ICALL                                         $4      
         13        SEND_VAR                                                 $4
         14        DO_ICALL                                         $5      
         15        FETCH_DIM_R                                      ~6      $2, $5
         16      > RETURN                                                   ~6
   12    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FJ5ua1%3A9%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
148.08 ms | 1403 KiB | 22 Q