3v4l.org

run code in 300+ PHP versions simultaneously
<?php function format_array($pattern, array $array) { return array_map( function (array $data) use ($pattern) { return preg_replace_callback( '/\{(\w+)\}/', function (array $match) use ($data) { return $data[$match[1]]; }, $pattern ); }, $array ); } $array = array( 1 => array( 'quote' => 'To be or not to be', 'citation' => 'Hamlet' ), 2 => array( 'quote' => 'The left hand knows that the right hand is doing', 'citation' => 'President Bush' ), 3 => array( 'quote' => 'Another quote', 'citation' => 'Another person' ) ); $array = format_array('{quote} – {citation}', $array); print_r($array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/laHR4
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ASSIGN                                                   !0, <array>
   31     1        INIT_FCALL                                               'format_array'
          2        SEND_VAL                                                 '%7Bquote%7D+%E2%80%93+%7Bcitation%7D'
          3        SEND_VAR                                                 !0
          4        DO_FCALL                                      0  $2      
          5        ASSIGN                                                   !0, $2
   33     6        INIT_FCALL                                               'print_r'
          7        SEND_VAR                                                 !0
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function format_array:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/laHR4
function name:  format_array
number of ops:  10
compiled vars:  !0 = $pattern, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        INIT_FCALL                                               'array_map'
    5     3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlaHR4%3A5%240'
          4        BIND_LEXICAL                                             ~2, !0
   11     5        SEND_VAL                                                 ~2
   12     6        SEND_VAR                                                 !1
          7        DO_ICALL                                         $3      
          8      > RETURN                                                   $3
   14     9*     > RETURN                                                   null

End of function format_array

Function %00%7Bclosure%7D%2Fin%2FlaHR4%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/laHR4
function name:  {closure}
number of ops:  11
compiled vars:  !0 = $data, !1 = $pattern
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
    6     2        INIT_FCALL                                               'preg_replace_callback'
    7     3        SEND_VAL                                                 '%2F%5C%7B%28%5Cw%2B%29%5C%7D%2F'
    8     4        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FlaHR4%3A8%241'
          5        BIND_LEXICAL                                             ~2, !0
          6        SEND_VAL                                                 ~2
    9     7        SEND_VAR                                                 !1
          8        DO_ICALL                                         $3      
          9      > RETURN                                                   $3
   11    10*     > RETURN                                                   null

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

Function %00%7Bclosure%7D%2Fin%2FlaHR4%3A8%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/laHR4
function name:  {closure}
number of ops:  6
compiled vars:  !0 = $match, !1 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        FETCH_DIM_R                                      ~2      !0, 1
          3        FETCH_DIM_R                                      ~3      !1, ~2
          4      > RETURN                                                   ~3
          5*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FlaHR4%3A8%241

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.79 ms | 1403 KiB | 20 Q