3v4l.org

run code in 500+ PHP versions simultaneously
<?php $string = "I have some fruits like [name], [another_name] and [one_another_name]"; $fruits_array = array("Banana", "Apple", "Orange"); $string = preg_replace_callback( '/\[[^]]+\]/', function ($matches) use (&$fruits_array) { return array_shift($fruits_array); }, $string ); echo $string;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KVqae
function name:  (null)
number of ops:  12
compiled vars:  !0 = $string, !1 = $fruits_array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, 'I+have+some+fruits+like+%5Bname%5D%2C+%5Banother_name%5D+and+%5Bone_another_name%5D'
    4     1        ASSIGN                                                       !1, <array>
    6     2        INIT_FCALL                                                   'preg_replace_callback'
    7     3        SEND_VAL                                                     '%2F%5C%5B%5B%5E%5D%5D%2B%5C%5D%2F'
    8     4        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          5        BIND_LEXICAL                                                 ~4, !1
   10     6        SEND_VAL                                                     ~4
   11     7        SEND_VAR                                                     !0
    6     8        DO_ICALL                                             $5      
          9        ASSIGN                                                       !0, $5
   14    10        ECHO                                                         !0
   15    11      > 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/KVqae
function name:  {closure:/in/KVqae:8}
number of ops:  7
compiled vars:  !0 = $matches, !1 = $fruits_array
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    8     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
    9     2        INIT_FCALL                                                   'array_shift'
          3        SEND_REF                                                     !1
          4        DO_ICALL                                             $2      
          5      > RETURN                                                       $2
   10     6*     > RETURN                                                       null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
143.23 ms | 2034 KiB | 15 Q