3v4l.org

run code in 300+ PHP versions simultaneously
<?php function spin($string) { return preg_replace_callback('/{(?<list>[^{}]+)}/', function ($match) { $list = explode('|', $match['list']); return $list[array_rand($list)]; }, $string); } $sentence = '{Please|Just} make this {cool|awesome|random} test sentence {rotate {quickly|fast} and random|spin and be random}'; echo spin($sentence);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YTDGu
function name:  (null)
number of ops:  6
compiled vars:  !0 = $sentence
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     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'
   13     1        INIT_FCALL                                               'spin'
          2        SEND_VAR                                                 !0
          3        DO_FCALL                                      0  $2      
          4        ECHO                                                     $2
          5      > RETURN                                                   1

Function spin:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/YTDGu
function name:  spin
number of ops:  9
compiled vars:  !0 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
    5     1        INIT_FCALL                                               'preg_replace_callback'
          2        SEND_VAL                                                 '%2F%7B%28%3F%3Clist%3E%5B%5E%7B%7D%5D%2B%29%7D%2F'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FYTDGu%3A5%240'
    8     4        SEND_VAL                                                 ~1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $2      
          7      > RETURN                                                   $2
    9     8*     > RETURN                                                   null

End of function spin

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

End of function %00%7Bclosure%7D%2Fin%2FYTDGu%3A5%240

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.04 ms | 1399 KiB | 20 Q