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}'; $sentences = []; for($i = 0; $i < 1000; $i++) { $sentences[] = sentence_spinning($sentence); } var_dump(array_values(array_unique($sentences))); 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; }
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 44) Position 1 = 12, Position 2 = 4
Branch analysis from position: 12
Branch analysis from position: 4
filename:       /in/8jOAt
function name:  (null)
number of ops:  22
compiled vars:  !0 = $sentence, !1 = $sentences, !2 = $i
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'
    5     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, 0
          3      > JMP                                                      ->10
    8     4    >   INIT_FCALL_BY_NAME                                       'sentence_spinning'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0  $7      
          7        ASSIGN_DIM                                               !1
          8        OP_DATA                                                  $7
    6     9        PRE_INC                                                  !2
         10    >   IS_SMALLER                                               !2, 1000
         11      > JMPNZ                                                    ~9, ->4
   11    12    >   INIT_FCALL                                               'var_dump'
         13        INIT_FCALL                                               'array_values'
         14        INIT_FCALL                                               'array_unique'
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $10     
         17        SEND_VAR                                                 $10
         18        DO_ICALL                                         $11     
         19        SEND_VAR                                                 $11
         20        DO_ICALL                                                 
   24    21      > 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/8jOAt
function name:  sentence_spinning
number of ops:  14
compiled vars:  !0 = $str, !1 = $count
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   17     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%2F8jOAt%3A17%240'
   20     4        SEND_VAL                                                 ~2
          5        SEND_VAR                                                 !0
          6        SEND_VAL                                                 -1
          7        SEND_REF                                                 !1
          8        DO_ICALL                                         $3      
   17     9        ASSIGN                                                   !0, $3
   21    10        IS_NOT_IDENTICAL                                         !1, 0
         11      > JMPNZ                                                    ~5, ->1
   23    12    > > RETURN                                                   !0
   24    13*     > RETURN                                                   null

End of function sentence_spinning

Function %00%7Bclosure%7D%2Fin%2F8jOAt%3A17%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/8jOAt
function name:  {closure}
number of ops:  18
compiled vars:  !0 = $matches
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
   19     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
   20    17*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2F8jOAt%3A17%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.71 ms | 1400 KiB | 27 Q