3v4l.org

run code in 300+ PHP versions simultaneously
<?php function map(array $array, array $keys) { $filter = function ($node) { return $node; }; foreach (array_reverse($keys) as $key) { $filter = function ($node) use ($filter, $key) { if ($key == '*') { return array_map(function ($branch) use ($filter) { return $filter($branch); }, $node); } return $filter($node[$key]); }; } return $filter($array); } $array = [ 'a' => [ 'b' => [ [ 'c' => 'foo', ], [ 'c' => 'bar', ], [ 'c' => 'qux', ], ], ], ]; $keys = ['a', '*', '*', 'c']; var_dump(map($array, $keys));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dGgpp
function name:  (null)
number of ops:  10
compiled vars:  !0 = $array, !1 = $keys
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   ASSIGN                                                   !0, <array>
   42     1        ASSIGN                                                   !1, <array>
   44     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'map'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function map:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 14
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 14
Branch analysis from position: 9
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/dGgpp
function name:  map
number of ops:  20
compiled vars:  !0 = $array, !1 = $keys, !2 = $filter, !3 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FdGgpp%3A5%240'
          3        ASSIGN                                                   !2, ~4
    9     4        INIT_FCALL                                               'array_reverse'
          5        SEND_VAR                                                 !1
          6        DO_ICALL                                         $6      
          7      > FE_RESET_R                                       $7      $6, ->14
          8    > > FE_FETCH_R                                               $7, !3, ->14
   11     9    >   DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FdGgpp%3A11%241'
         10        BIND_LEXICAL                                             ~8, !2
         11        BIND_LEXICAL                                             ~8, !3
         12        ASSIGN                                                   !2, ~8
    9    13      > JMP                                                      ->8
         14    >   FE_FREE                                                  $7
   23    15        INIT_DYNAMIC_CALL                                        !2
         16        SEND_VAR_EX                                              !0
         17        DO_FCALL                                      0  $10     
         18      > RETURN                                                   $10
   24    19*     > RETURN                                                   null

End of function map

Function %00%7Bclosure%7D%2Fin%2FdGgpp%3A5%240:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dGgpp
function name:  {closure}
number of ops:  3
compiled vars:  !0 = $node
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1      > RETURN                                                   !0
    8     2*     > RETURN                                                   null

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

Function %00%7Bclosure%7D%2Fin%2FdGgpp%3A11%241:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 12
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dGgpp
function name:  {closure}
number of ops:  19
compiled vars:  !0 = $node, !1 = $filter, !2 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        BIND_STATIC                                              !2
   13     3        IS_EQUAL                                                 !2, '%2A'
          4      > JMPZ                                                     ~3, ->12
   15     5    >   INIT_FCALL                                               'array_map'
          6        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FdGgpp%3A15%242'
          7        BIND_LEXICAL                                             ~4, !1
   18     8        SEND_VAL                                                 ~4
          9        SEND_VAR                                                 !0
         10        DO_ICALL                                         $5      
         11      > RETURN                                                   $5
   20    12    >   INIT_DYNAMIC_CALL                                        !1
         13        CHECK_FUNC_ARG                                           
         14        FETCH_DIM_FUNC_ARG                               $6      !0, !2
         15        SEND_FUNC_ARG                                            $6
         16        DO_FCALL                                      0  $7      
         17      > RETURN                                                   $7
   21    18*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FdGgpp%3A11%241

Function %00%7Bclosure%7D%2Fin%2FdGgpp%3A15%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/dGgpp
function name:  {closure}
number of ops:  7
compiled vars:  !0 = $branch, !1 = $filter
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
   17     2        INIT_DYNAMIC_CALL                                        !1
          3        SEND_VAR_EX                                              !0
          4        DO_FCALL                                      0  $2      
          5      > RETURN                                                   $2
   18     6*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FdGgpp%3A15%242

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
163.6 ms | 1407 KiB | 20 Q