3v4l.org

run code in 300+ PHP versions simultaneously
<?php $text = "Welcome to [city]. I want [city] to be a random version each time. [city] should not be the same [city] each time."; $keyword = "[city]"; $values = ["Orlando", "Dallas", "Atlanta", "Detroit", "Tampa", "Miami"]; shuffle($values); echo preg_replace_callback( '/' . preg_quote($keyword) . '/', function() use(&$values) { return array_pop($values); }, $text );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iMTOR
function name:  (null)
number of ops:  20
compiled vars:  !0 = $text, !1 = $keyword, !2 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'Welcome+to+%5Bcity%5D.+I+want+%5Bcity%5D+to+be+a+random+version+each+time.+%5Bcity%5D+should+not+be+the+same+%5Bcity%5D+each+time.'
    5     1        ASSIGN                                                   !1, '%5Bcity%5D'
    6     2        ASSIGN                                                   !2, <array>
    7     3        INIT_FCALL                                               'shuffle'
          4        SEND_REF                                                 !2
          5        DO_ICALL                                                 
    9     6        INIT_FCALL                                               'preg_replace_callback'
   10     7        INIT_FCALL                                               'preg_quote'
          8        SEND_VAR                                                 !1
          9        DO_ICALL                                         $7      
         10        CONCAT                                           ~8      '%2F', $7
         11        CONCAT                                           ~9      ~8, '%2F'
         12        SEND_VAL                                                 ~9
   11    13        DECLARE_LAMBDA_FUNCTION                          ~10     [0]
         14        BIND_LEXICAL                                             ~10, !2
         15        SEND_VAL                                                 ~10
   12    16        SEND_VAR                                                 !0
    9    17        DO_ICALL                                         $11     
   12    18        ECHO                                                     $11
   13    19      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iMTOR
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $values
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   BIND_STATIC                                              !0
          1        INIT_FCALL                                               'array_pop'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                         $1      
          4      > RETURN                                                   $1
          5*     > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.23 ms | 1002 KiB | 17 Q