3v4l.org

run code in 300+ PHP versions simultaneously
<?php $string = "My starting year is {{current_year}} and my grad year is {{grad_year}}"; $placeholders = [ "{{current_year}}" => date("Y"), "{{grad_year}}" => date("Y") + 4 ]; array_walk($placeholders, function($value, $key) use (&$string) { $string = str_replace($key, $value, $string); }); echo $string;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/KKi8Y
function name:  (null)
number of ops:  19
compiled vars:  !0 = $string, !1 = $placeholders
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, 'My+starting+year+is+%7B%7Bcurrent_year%7D%7D+and+my+grad+year+is+%7B%7Bgrad_year%7D%7D'
    5     1        INIT_FCALL                                               'date'
          2        SEND_VAL                                                 'Y'
          3        DO_ICALL                                         $3      
          4        INIT_ARRAY                                       ~4      $3, '%7B%7Bcurrent_year%7D%7D'
    6     5        INIT_FCALL                                               'date'
          6        SEND_VAL                                                 'Y'
          7        DO_ICALL                                         $5      
          8        ADD                                              ~6      $5, 4
          9        ADD_ARRAY_ELEMENT                                ~4      ~6, '%7B%7Bgrad_year%7D%7D'
    4    10        ASSIGN                                                   !1, ~4
   10    11        INIT_FCALL                                               'array_walk'
         12        SEND_REF                                                 !1
         13        DECLARE_LAMBDA_FUNCTION                          ~8      [0]
         14        BIND_LEXICAL                                             ~8, !0
   12    15        SEND_VAL                                                 ~8
   10    16        DO_ICALL                                                 
   14    17        ECHO                                                     !0
   15    18      > 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/KKi8Y
function name:  {closure}
number of ops:  10
compiled vars:  !0 = $value, !1 = $key, !2 = $string
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   10     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        BIND_STATIC                                              !2
   11     3        INIT_FCALL                                               'str_replace'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        SEND_VAR                                                 !2
          7        DO_ICALL                                         $3      
          8        ASSIGN                                                   !2, $3
   12     9      > RETURN                                                   null

End of Dynamic Function 0

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.67 ms | 955 KiB | 16 Q