3v4l.org

run code in 500+ PHP versions simultaneously
<?php $array1 = [ 31 => ['a', 'b'], 49 => ['c', 'd'], 28 => ['e', 'f'] ]; $array2 = [1, 2, 3]; function mapper($array1, $array2) { $i = -1; var_export( array_map(fn($row) => array_merge($row, [$array2[++$i]]), $array1) ); } function looper($array1, $array2) { $i = -1; foreach ($array1 as &$row) { array_push($row, $array2[++$i]); } var_export($array1); } function walker($array1, $array2) { $i = -1; array_walk($array1, fn(&$row, $k) => array_push($row, $array2[++$i])); var_export($array1); } mapper($array1, $array2); echo "\n---\n"; looper($array1, $array2); echo "\n---\n"; walker($array1, $array2);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/afGvZ
function name:  (null)
number of ops:  17
compiled vars:  !0 = $array1, !1 = $array2
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    9     1        ASSIGN                                                       !1, <array>
   32     2        INIT_FCALL                                                   'mapper'
          3        SEND_VAR                                                     !0
          4        SEND_VAR                                                     !1
          5        DO_FCALL                                          0          
   33     6        ECHO                                                         '%0A---%0A'
   34     7        INIT_FCALL                                                   'looper'
          8        SEND_VAR                                                     !0
          9        SEND_VAR                                                     !1
         10        DO_FCALL                                          0          
   35    11        ECHO                                                         '%0A---%0A'
   36    12        INIT_FCALL                                                   'walker'
         13        SEND_VAR                                                     !0
         14        SEND_VAR                                                     !1
         15        DO_FCALL                                          0          
         16      > RETURN                                                       1

Function mapper:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/afGvZ
function name:  mapper
number of ops:  14
compiled vars:  !0 = $array1, !1 = $array2, !2 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   11     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   12     2        ASSIGN                                                       !2, -1
   13     3        INIT_FCALL                                                   'var_export'
   14     4        INIT_FCALL                                                   'array_map'
          5        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          6        BIND_LEXICAL                                                 ~4, !1
          7        BIND_LEXICAL                                                 ~4, !2
          8        SEND_VAL                                                     ~4
          9        SEND_VAR                                                     !0
         10        DO_ICALL                                             $5      
         11        SEND_VAR                                                     $5
   13    12        DO_ICALL                                                     
   16    13      > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/afGvZ
function name:  {closure:mapper():14}
number of ops:  12
compiled vars:  !0 = $row, !1 = $array2, !2 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   14     0  E >   RECV                                                 !0      
          1        BIND_STATIC                                                  !1
          2        BIND_STATIC                                                  !2
          3        INIT_FCALL                                                   'array_merge'
          4        SEND_VAR                                                     !0
          5        PRE_INC                                              ~3      !2
          6        FETCH_DIM_R                                          ~4      !1, ~3
          7        INIT_ARRAY                                           ~5      ~4
          8        SEND_VAL                                                     ~5
          9        DO_ICALL                                             $6      
         10      > RETURN                                                       $6
         11*     > RETURN                                                       null

End of Dynamic Function 0

End of function mapper

Function looper:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 4, Position 2 = 12
Branch analysis from position: 4
2 jumps found. (Code = 126) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
filename:       /in/afGvZ
function name:  looper
number of ops:  17
compiled vars:  !0 = $array1, !1 = $array2, !2 = $i, !3 = $row
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   18     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   19     2        ASSIGN                                                       !2, -1
   20     3      > FE_RESET_RW                                          $5      !0, ->12
          4    > > FE_FETCH_RW                                                  $5, !3, ->12
   21     5    >   INIT_FCALL                                                   'array_push'
          6        SEND_REF                                                     !3
          7        PRE_INC                                              ~6      !2
          8        FETCH_DIM_R                                          ~7      !1, ~6
          9        SEND_VAL                                                     ~7
         10        DO_ICALL                                                     
   20    11      > JMP                                                          ->4
         12    >   FE_FREE                                                      $5
   23    13        INIT_FCALL                                                   'var_export'
         14        SEND_VAR                                                     !0
         15        DO_ICALL                                                     
   24    16      > RETURN                                                       null

End of function looper

Function walker:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/afGvZ
function name:  walker
number of ops:  14
compiled vars:  !0 = $array1, !1 = $array2, !2 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   26     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   27     2        ASSIGN                                                       !2, -1
   28     3        INIT_FCALL                                                   'array_walk'
          4        SEND_REF                                                     !0
          5        DECLARE_LAMBDA_FUNCTION                              ~4      [0]
          6        BIND_LEXICAL                                                 ~4, !1
          7        BIND_LEXICAL                                                 ~4, !2
          8        SEND_VAL                                                     ~4
          9        DO_ICALL                                                     
   29    10        INIT_FCALL                                                   'var_export'
         11        SEND_VAR                                                     !0
         12        DO_ICALL                                                     
   30    13      > RETURN                                                       null


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/afGvZ
function name:  {closure:walker():28}
number of ops:  12
compiled vars:  !0 = $row, !1 = $k, !2 = $array2, !3 = $i
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   28     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        BIND_STATIC                                                  !2
          3        BIND_STATIC                                                  !3
          4        INIT_FCALL                                                   'array_push'
          5        SEND_REF                                                     !0
          6        PRE_INC                                              ~4      !3
          7        FETCH_DIM_R                                          ~5      !2, ~4
          8        SEND_VAL                                                     ~5
          9        DO_ICALL                                             $6      
         10      > RETURN                                                       $6
         11*     > RETURN                                                       null

End of Dynamic Function 0

End of function walker

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
219.7 ms | 2005 KiB | 21 Q