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) { $new_str = preg_replace_callback('#\{([^{}]*)\}#im', function($matches) { $rand = array_rand($split = explode('|', $matches[1])); return $split[$rand]; }, $str); return ($new_str !== $str) ? sentence_spinning($new_str) : $str; } echo sentence_spinning($sentence);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/qcNiC
function name:  (null)
number of ops:  6
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'
   16     1        INIT_FCALL                                               'sentence_spinning'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

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

End of function sentence_spinning

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

End of function %00%7Bclosure%7D%2Fin%2FqcNiC%3A7%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.67 ms | 1402 KiB | 20 Q