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) { return ($rand = array_rand($split = explode('|', $matches[1])))[$rand]; return $split[$rand]; }, $str); if ($new_str !== $str) $str = sentence_spinning($new_str); return $str; } echo sentence_spinning($sentence);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D619p
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'
   18     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 = 14
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/D619p
function name:  sentence_spinning
number of ops:  16
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%2FD619p%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, ->14
         10    >   INIT_FCALL_BY_NAME                                       'sentence_spinning'
         11        SEND_VAR_EX                                              !1
         12        DO_FCALL                                      0  $6      
         13        ASSIGN                                                   !0, $6
   15    14    > > RETURN                                                   !0
   16    15*     > RETURN                                                   null

End of function sentence_spinning

Function %00%7Bclosure%7D%2Fin%2FD619p%3A7%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/D619p
function name:  {closure}
number of ops:  16
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                                           ~7      !1, $6
         11        FETCH_DIM_R                                      ~8      ~7, !1
         12      > RETURN                                                   ~8
   10    13*       FETCH_DIM_R                                      ~9      !2, !1
         14*       RETURN                                                   ~9
   11    15*     > RETURN                                                   null

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

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.28 ms | 1398 KiB | 21 Q